#include "compiler_defs.h" #include "C8051f380_defs.h" #include <stddef.h> struct MASTER { int cmd[2]; }; xdata struct MASTER mstr; //----------------------------------------------------------------------------- void main(void) { while(1) { char a; if(mstr.cmd==0)a=0; if(mstr.cmd[1]==0)a=0; } }
Hi guys:
The attached code has a structure with one member array of 2 elements. This code compiles and it shouldn't: note in main() that there's access to the member without an index and the compiler is not giving any error.
What's going on here?
I am using Silabs 8051F380 processorC51 , compiler V9.55, and BL linker V6.22
Thanks!!!
Check it out:
stackoverflow.com/.../reference-of-an-array-without-index-in-c
HI Chen.
The thing here is that the if(...) is treated as an expression referenced to a pointer. Never thought about that! If I try to assign a value then the compiler complains rightfully.
Thanks for your input!!!
juance said:Never thought about that!
Really?
That's a pretty basic 'C' thing: the name of an array is, effectively, a pointer to the first element.
http://c-faq.com/aryptr/