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

发布于 2025-01-04 18:08:48 字数 983 浏览 0 评论 0原文

我有 4 个“#defines”:

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

我有一个像这样声明的 3 维数组:

    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]

有什么问题吗?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

少跟Wǒ拽 2025-01-11 18:08:48

您可以将其作为“unsigned char *”传递。 (即三个星号)

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

千纸鹤带着心事 2025-01-11 18:08:48

通过这种方式,

函数的原型必须是

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

or

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)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文