如何在C中传递三维数组的地址?

时间:2012-02-11 10:05:05

标签: c parameters multidimensional-array

我有4个“#defines”:

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

我有一个如下所示的三维数组:

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

我有一个“for”循环如下:

    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]);
        }
    }

“HL_flash2ram”函数的原型是

    void HL_flash2ram(long addr, unsigned char* );

然而,在编译时,我收到警告:

    warning C182: pointer to different objects

我正在使用KEIL编译器。我甚至尝试了以下方法:

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

有什么问题?

2 个答案:

答案 0 :(得分:0)

您可以将其作为'unsigned char * '传递。 (这是三个星号)

答案 1 :(得分:0)

通过这种方式

函数的原型必须是

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

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

但在最后一种情况下,要执行元素arr [a] [b] [c]的访问

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