General Define Usage

Create a define
#define	SENS_RH_IS_USED     //Comment out or include
#define	NUM_OF_ANODES	2
Use a define
#if NUM_OF_ANODES == 2
#endif
#ifdef
#endif

#ifndef
#endif

#ifdef
#elif           //Don't use "#else if", its actually interpreted as just #else
#else
#endif

#if defined(PIC18F87J50_PIM) || defined(PIC18F46J50_PIM) || defined(PIC18F_STARTER_KIT_1)
#endif

#if defined(SENS_RH_IS_USED) && (SENS_RH_MODEL == 2)
#endif

#if defined(ENABLE_SENSOR) && !defined(__JTAG_DEBUG)
#endif
Define if not already defined
#ifndef MY_DEFINE_NAME
    #define MY_DEFINE_NAME    1
#endif

Define using another define

#define MY_DEFINE_1		MY_DEFINE_2

Multi Line Continuation Character

Use the ‘\’ backslash character at the end of each line except for the last.
If you have any comments surround them with /* */ (don’t use // )

Can you use string in an ‘#if’ statement in C programming?

No, strings are not supported by C. Use something like this instead:

#define SCD30           0
#define AM2322          1
#define DHT20           2
#define COMBO_SENSOR_SENORS_FITTED          SCD30      //<<<<<SET SENSOR IN USE (SCD30 or AM2322 or DHT20)

#if COMBO_SENSOR_SENORS_FITTED == AM2322

#elif COMBO_SENSOR_SENORS_FITTED == DHT20

#endif
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *