Precompiler directives - is there a case statement?

Hi,

I'm working with a arduino project that uses a GSM shield to send SMS. I've made three units, all with the same functionality but each with a different GSM shield (because they keep going out of stock or becoming obselete)

Each of my three devices needs some very minor code changes to work, and I've implemented this using pre-comiler directives to include the extra lines required. (pseudo code follows.....)

ifdef SM5100B

// Do stuff specific for SM5100B module

endif

ifdef TELIT

// Do stuff specific for TELIT module

endif

With three different modules, I can't help feeling that a 'case' statement of some sort would be more appropriate, but I can't find any mention of any such pre-compiler option.

Is there?

Cheers

Never heard of one... It is antedeluvian technology (the C preprocessor).

Hi, There are just if, elif, else and endif. If you look through the source code for the Arduino libraries you will see how these are used for a similar purpose to yours - they are sometimes used in combination to deal with the different Arduino processors (ATMega8,168,328 etc) and different clock speeds.

If you look in Servo.cpp you will see what appear to be nested directives - something I didn't know was possible until seeing it now !

Duane B

rcarduino.blogspot.com

i, There are just if, elif, else and endif. I

..and ifdef and ifndef, undef...

There sure is however it is not a pre-compiler option, rather a method of running/generating code during compile time.

Have you ever run into template meta-programming. All sorts of compile time conditional statements can be reproduced. However it has an extremely steep learning curve.

http://en.wikipedia.org/wiki/Template_metaprogramming http://en.wikibooks.org/wiki/C++_Programming/Templates/Template_Meta-Programming