access out of range

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

access out of range

跳至解决方案
2,380 次查看
electronicfan
Contributor II
hello,

i have a little problem:

I get an error message: access out of range

my code:

unsigned char my_func(void)
{
.....
return(array[8]);
}

This function is outsite of main.c
Hope somebody can help me.
标签 (1)
标记 (1)
0 项奖励
回复
1 解答
1,316 次查看
bigmac
Specialist III
Hello electronicfan,

Assuming that you decare an array to contain eight elements,

unsigned char array[8];

The first element of the array will be array[0] and the last element will be array[7].  The element array[8] does not exist.

Regards,
Mac

在原帖中查看解决方案

0 项奖励
回复
3 回复数
1,316 次查看
bigmac
Specialist III
Hello,

What size have you declared for the global array?  To return the array[8] element, the array size would need to be 9, or more.

Regards,
Mac

0 项奖励
回复
1,316 次查看
electronicfan
Contributor II
hello Mac,

i have a global array of 8 bytes and i will return all 8 bytes to my main function.

Hope you can help me.


electronicfan



0 项奖励
回复
1,317 次查看
bigmac
Specialist III
Hello electronicfan,

Assuming that you decare an array to contain eight elements,

unsigned char array[8];

The first element of the array will be array[0] and the last element will be array[7].  The element array[8] does not exist.

Regards,
Mac
0 项奖励
回复