This is a stupid question, but I can’t work it out and it’s beginning to irritate me!
I have the following (reg is a global):
#define CS 4
#define DS 5
unsigned char reg[6] = {0, 0, 0, 0, 0, 0x10};
Now, I would expect reg[DS] to access element 5 of array reg (0x10). However, when debugging (VC2010), Visual Studio is claiming that DS is zero and the first element is accessed. Is it me, or is Visual Studio being stupid?
Yes.
Unless you have redefined the macro
DSsomewhere else in the code.Macros are evaluated at pre-compilation. So if you defined
DSas5then what goes to the compiler for compilation isreg[5].Also, You cannot check a macro value at run-time because they do not exist at run-time, they are already substituted with whatever value they are defined as.