I declare a variable unsigned char bdata Kde in a.c.
[in file a.c] unsigned char bdata Kde;
[in file b.c] #include <stdio.h> ..... extern unsigned char bdata Kde; sbit testbit=Kde^1; void main(void) {......}
sbit MODEM_RING = P1 ^ 4; #define MODEM_RING 0x04 // ring input My question is, why was there no warning? Because #define is a preprocessor directive. These replacements are made before the compiler ever sees the C code. For the same reason, I can
#define if
That's interesting, and I thank you for the explanation. I'm still puzzling as to why I would want this. Is there a lobby of C programmers who would be unhappy if they received warnings when they had their "if"s removed? Is this beyond the realm of state of the art?
"I'm still puzzling as to why I would want this." I think that was Jon's point - just because you can do something doesn't make it a Good Thing! As I said, you need to look at the preprocessor listing to see the text which the Compiler actually receives; the Compiler can't possibly give warnings about the input to the preprocessor, because it never sees that! Perhaps you need to start using lint, or similar?
I was able to use a search engine to find "gimpel software lint". While doing so, I saw a couple of interesting quotes: http://www.tldp.org/LDP/LG/issue51/pramode.html "Thou shalt run lint frequently and study its pronouncements with care, for verily its perception and judgment oft exceed thine." -Henry Spencer, "The Ten Commandments for C Programmers" http://www.lysator.liu.se/c/c-faq/c-13.html ...many modern compilers attempt to diagnose almost as many problems as a good lint does.
...many modern compilers attempt to diagnose almost as many problems as a good lint does. I use Gimpel Sofware's PC-lint and several (9) modern compilers. None of the compilers come close to catching what lint does!