Preprocessor "#if" directive undocumented

The reference documentation appears to be incomplete regarding the preprocessor. It only mentions the #define and #include directives.

"#if", "#else" and "#endif" apear not to be documented in the reference - are they documented anywhere else in the Arduino documentation?

I found chapter 17 of the O'Reilly Arduino cookbook online book;
it mentioned that C preprocessor is documented at The C Preprocessor: 1. The C Preprocessor

The arduino reference documentation should either link to that documentation or document the missing directives itself.

I think that's probably a good thing. I think that probably a lot of new programmers would stumble on the fact that there's two types of 'if'. Considering there's only two good reasons to use #if in C++. Those are

  • Header guards - which only relatively advanced Arduino users would need to know about.
  • Writing architecture specific/cross platform code - non issue for Arduino

It's probably best that #if, #else and #endif remain undocumented IMO.

Yes I think it would be too overwhelming for the target user(and the web developers) to have a full C++ reference in the Arduino reference. There are other sites that provide that but it would be nice if they provided a link to one of them from the reference page.

would be to document the build process, it would be to document the bugs plaguing the pre pre compiler (at least up to 1.6.6), and explain the difference between #if in C / C ++ and the Arduino.
Still we do not want to remain such novices

Why is writing Architecture specific code not an issue for Arduino? That's exactly what I need the preprocessor stuff for.

1 Like

Writing architecture specific code is explained in Arduino IDE 1.5: Library specification · arduino/Arduino Wiki · GitHub of course this information is not specific to libraries so it might not be the first place someone would look for it. I think the idea is that the information the target user would want is in the reference and the information for developers is in the GitHub wiki but this does make it a bit difficult to transition between the two because you would need to stumble across the GitHub wiki.

I know that:
-For smaller branches, if is faster. [Generally smaller in data size.]
-For larger branches, switch is faster. [Generally larger in data size.]

Is #if any faster than switch for large branches, or is switch just a reworded pure #if? I would suspect that there is other code included in switch as well.

'#if' and 'if' are not the same thing.
'#if' is a preprocessor directive
'if' is a C language statement

Pete