D
deepak
Using 'char' as an array index is an undefined behavior?
Using 'char' as an array index is an undefined behavior?
deepak said:Using 'char' as an array index is an undefined behavior?
deepak said:Using 'char' as an array index is an undefined behavior?
[/QUOTE]Using 'char' as an array index is an undefined behavior?
No, but if 'char' is 8-bit and signed, and contains an 8-bit character,
then it is negative.
Using 'char' as an array index is an undefined behavior?
Richard Heathfield said:deepak said:
No, but indexing outside the bounds of an array does invoke undefined
behaviour. If the value stored in the char is negative (which it can be if
char is signed by default) or greater than or equal to the number of
elements in the array, the behaviour is undefined.
Serve said:Richard Heathfield said:deepak said:
No, but indexing outside the bounds of an array does invoke undefined
behaviour. If the value stored in the char is negative (which it can be if
char is signed by default) or greater than or equal to the number of
elements in the array, the behaviour is undefined.
int array[10] = { 0,1,2,3,4,5,6,7,8,9};
int *p = &array[4];
signed char index = -1; // signed for clarity
printf("%d\n", p[index]);
are you guys saying that any negative index is undefined behaviour or just
that if you dereference before &array[0]?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.