Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: #define, #ifdef, #elsif, #endif?

  1. #1
    Junior Member
    Join Date
    Jan 2020
    Posts
    19

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

    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

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,366
    Yes, it does. The Arduino IDE uses the gcc compiler, including the pre-processor.
    Have you installed the Arduino IDE plus Teensyduino yet?

    Pete

  3. #3
    Senior Member
    Join Date
    Feb 2015
    Location
    Finland
    Posts
    189
    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.

  4. #4
    Junior Member
    Join Date
    Jan 2020
    Posts
    19
    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.

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,116
    I generally try to follow Arduino's API style guidelines for most Teensy features and libraries. While the language is C++ (without RTTI & exceptions), the C++ features like templates and STL are generally not used, because of their complex syntax.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •