#define, #ifdef, #elsif, #endif?

Status
Not open for further replies.

starfire151

Active member
I'm sorry if this has been answered before but, having come from a 'C' background, I was wondering if the Arduino / Teensy environment allows for conditional compilations using the pre-processor directives #define, #ifdef, #elsif, and #endif, (or something similar)?

It seems it would be handy to include verbose printout information in a debug mode and to not include those outputs in a runtime mode.

Is there another standard way to do this?

Thanks
 
Yes, it does. The Arduino IDE uses the gcc compiler, including the pre-processor.
Have you installed the Arduino IDE plus Teensyduino yet?

Pete
 
To expand on what Pete (el_supremo) already answered, the Arduino sketches are actually just a subset of C++ compiled using GCC, with some autogenerated code (like function prototypes, which may look odd at first).

Coming from C, you'll find that the subset of C++ that is used, is very intuitive and useful. You'll eventually need to understand how classes extend the functionality of structs to objects, and possibly how templates are used in libraries, but just about everything you know from C is directly applicable; you'll just need to extend that a bit with this subset of C++.

The full feature set of C++ is not used; only a small subset. For example, exceptions are not used. Also, the standard C++ (or C) libraries are not used in the Arduino environment; only the Arduino (and Teensyduino!) libraries are.

Therefore, if you read C++ tutorials or a book on C++, it is a good idea to concentrate on the features that are actually used in Arduino code. In fact, if you feel confident in your C skills, I'd recommend looking at the Arduino libraries (including Teensyduino) that Paul has written, and other libraries written by members here in this forum (depending on exactly what you personally are interested in), and then looking up any unfamiliar syntax and details at e.g. cplusplus.com.
 
Thanks, very much, for the responses. As always, el_supremo is very helpful and quick to respond! Thanks, also, for the additional information from Nominal Animal.

I have installed the Teensyduino IDE enhancement and have had successful loads to both Teensy 3.6 and Teensy 4.0 modules.

Thanks, again.
 
Status
Not open for further replies.
Back
Top