简体   繁体   中英

How do I pass the address of a 3-dimensional array in C?

I have 4 " #defines " :

    #define MAX_NO_OF_ROUTES    15
    #define MAX_STOPS_IN_ROUTE  50
    #define RAIL_SYMBOL_LEN     3
    #define READ_ADDR       25236

I have a 3-dimensional array declared like this :

    unsigned char ram_route_info[MAX_NO_OF_ROUTES][MAX_STOPS_IN_ROUTE][RAIL_SYMBOL_LEN];

I have a "for" loop as follows :

    for(i = 0 ; i < MAX_NO_OF_ROUTES ; ++i)
    {
        for(j = 0 ; j < MAX_STOPS_IN_ROUTE ; ++j)
        {
            // read from Flash into ram !!
            HL_flash2ram(READ_ADDR, &ram_route_info[i][j][0]);
        }
    }

The prototype of "HL_flash2ram" function is

    void HL_flash2ram(long addr, unsigned char* );

On compiling, however, I get the warning :

    warning C182: pointer to different objects

I'm using KEIL compiler. I've even tried the following :

    ram_route_info[i][j]
    &(ram_route_info[i][j])
    ram_route_info[i][j][0]

What's the problem ?

You can pass it as an 'unsigned char * '. (that is three asterisk)

Pass this way

prototype of the function must be

  void HL_flash2ram(long addr, unsigned char  arr[][MAX_STOPS_IN_ROUTE][RAIL_SYMBOL_LEN] );

or

void HL_flash2ram(long addr, unsigned char* arr);

But in the last case access to an element arr[a][b][c] is to be performed so

*(arr + a*MAX_STOPS_IN_ROUTE*RAIL_SYMBOL_LEN + b*RAIL_SYMBOL_LEN + c)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM