Simplest sketch doesn't compile

I am using 1.6.4 IDE with a 800 line sketch when it all went horribly wrong with compiler messages spewing out from what was good code. I cut the code down to what you see below and it this still goes wrong. Am I losing my mind...

This is the basic code

ifdef _X_
unsigned char x[2];
endif


unsigned char b()
{
  return 0;
}

unsigned char a()
{
  return b();
}

void loop(){}

void setup(){}

When the top three lines say

#ifdef _X_
unsigned char x[2];
#endif

The IDE says

does not compile and the IDE messages are:

definetest.ino: In function 'unsigned char a()':
definetest:27: error: 'b' was not declared in this scope
'b' was not declared in this scope

Where as

#ifdef _X_
//unsigned char x[2];
#endif

compiles

And so does

//#ifdef _X_
unsigned char x[2];
//#endif

Changing the order of the functions so b is in the code before a gives

C:\Users\Alan\AppData\Local\Temp\build3893539535880651798.tmp/core.a(main.cpp.o): In function main': D:\Arduino\_Tools\Arduino\arduino-1.6.4\hardware\arduino\avr\cores\arduino/main.cpp:40: undefined reference to setup'
D:\Arduino_Tools\Arduino\arduino-1.6.4\hardware\arduino\avr\cores\arduino/main.cpp:43: undefined reference to `loop'
collect2.exe: error: ld returned 1 exit status
Error compiling.

I am at a loss :frowning:

It's a known unwanted side effect of the way the IDE processes the #include files.
Try adding

char junk;

before the #ifdef

Pete

Use File + Preferences, and enable verbose mode when compiling. Look at the .cpp file that is created from the .ino file. All your questions will be answered.

What the fffffff!

Is that a feature??

When I have these kind of weird errors, usually I add

#include <Arduino.h>

at the top, and it fixes it.

Is that a feature??

It's a matter of the preprocessor team having a lot more people, with a lot more experience at writing parsers, using a lot better tools, than the people developing/maintaining the IDE.

Thanks guys, I'll get back on the job tomorrow now...