access out of range

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

access out of range

Jump to solution
1,906 Views
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.
Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
842 Views
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

View solution in original post

0 Kudos
Reply
3 Replies
842 Views
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 Kudos
Reply
842 Views
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 Kudos
Reply
843 Views
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 Kudos
Reply