How to assign a 2d array to a memory address.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dissectcode2
    New Member
    • Apr 2009
    • 32

    #1

    How to assign a 2d array to a memory address.

    HI - I have a 2d array of uint32's :

    Code:
    uint32 x[4][5];
    and I want that array to be assigned to a certain address (which is a set of registers) :

    Code:
    uint32 *addr = 0x12345678;
    HOW do I assign the 2d array to the address? I know it's not right but I want to do this:

    &x = addr;

    helppp
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    You can't assign an address to an array, you can onlyassign an address to a pointer.

    Now assuming your address points to a block of memory with the array you've given what you need is a pointer to an array of that type. To declare a pointer to an array you sound the name and * with ()

    int *a[5]; // An array of 5 pointers to ints

    int (*a)[5]; // A pointer to an array of ints

    So you would do

    uint32 (*addr)[4][5] = 0x12345678;

    If this is C++ you will need a cast. Then you can access this as

    (*addr)[2][1]

    Comment

    Working...