code8825 / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

#ifdef weirdness #987

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Compile sketch below
2.
3.

What is the expected output? What do you see instead?
I'd expect it to compile

What version of the Arduino software are you using? 1.0.1 On what operating 
system? Mac OSX (10.7.4) Which Arduino board are you using? none

Please provide any additional information below.
I've been trying to track down all kinds of weirdnesses with #ifdef's and 
simplified to the following failure case.

#define ZZZ

#ifndef ZZZ
blah blah blah
#endif

void setup() {
  int i=1;  
}
void loop() {
  int i=2;
}

This code should compile fine, i.e. ZZZ is defined so the "blah blah blah" 
should be ignored.  - but it generates a bug about setup and loop not being 
defined. 

even stranger, if a ";" (on its own or with a statement) is inserted on the 
line above the #ifndef e.g. 

#define ZZZ
int i=1;
#ifndef ZZZ
blah blah blah
#endif

void setup() {
  int i=1;  
}
void loop() {
  int i=2;
}

then it complains about the blah blah blah - i.e. it is ignoring the #ifndef. 

I see several complaints about #ifndef and #includes in the forums, but nothing 
about #ifndef and #ifdef's being ignored themselves. 

There are plenty more examples - it isn't just that "blah blah blah" is 
incorrect, for example ...

#define ZZZ

#ifndef ZZZ
int i=1;
#endif

void setup() {
  int i=1;  
}
void loop() {
  int i=2;
}

fails to compile, but if the #ifndef section is removed as in 

#define ZZZ

void setup() {
  int i=1;  
}
void loop() {
  int i=2;
}

Then it compiles. 

Original issue reported on code.google.com by mitra.ar...@gmail.com on 19 Jul 2012 at 6:44

GoogleCodeExporter commented 9 years ago
The pre-processing of Arduino sketches still has some limitations and this is 
one...  I'll clarify in the other issue.

Original comment by dmel...@gmail.com on 19 Jul 2012 at 2:23