Array of pointers like (*(volatile unsigned long *)0x40004000)

后端 未结 4 1036
借酒劲吻你
借酒劲吻你 2021-01-04 20:49

I am having a very hard time figuring out how to solve the following problem. I am on an embedded system with very little memory and want to minimize memory usage. Pointers

4条回答
  •  我在风中等你
    2021-01-04 21:13

    Usual way is to declare a struct, for example :

    struct RegsAtAddrA
    {
      unsigned int array1[10];
      char val1;
      // etc
    };
    

    then to access it :

    volatile RegsAtAddrA *pRegsA = (volatile RegsAtAddrA *) 0x40004000;
    pRegsA->val1= 'a';
    //etc
    

    EDIT: I just realized that I haven't answered the question. So, here it is :

    #include 
    unsigned long a=1;
    unsigned long b=2;
    volatile unsigned long *port_base_array[] = {
       &a,
       &b,
       //etc
    };
    int main()
    {
        std::cout<<"a="<<*port_base_array[0]<
                                                            
提交回复
热议问题