如何在 C 中传递 3 维数组的地址?
我有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将其作为“unsigned char *”传递。 (即三个星号)
You can pass it as an 'unsigned char *'. (that is three asterisk)
通过这种方式,
函数的原型必须是
or
但在最后一种情况下,要执行对元素 arr[a][b][c] 的访问,以便
Pass this way
prototype of the function must be
or
But in the last case access to an element arr[a][b][c] is to be performed so