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
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through resources like this. We hope you find it helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support here. If you need help with a problem please use one of the many online forums.

Comments

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