lpcware

LPCOpen bug : TRUE is false.

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by peufeu on Fri Aug 08 08:00:32 MST 2014
lpcopen2.12/lpc_chip_43xx/inc/lpc_types.h contains the following statement.

typedef enum {FALSE = 0, TRUE = !FALSE} Bool;


Compiling the following code with lpc_types.h included :

#if True
#pragma message "TRUE is TRUE"
#else
#pragma message "TRUE is FALSE"
#endif

#ifdef True
#pragma message "TRUE is Defined"
#else
#pragma message "TRUE is Not Defined"
#endif


Gives this result :

foo.c:40:9: note: #pragma message: TRUE is FALSE
foo.c:46:9: note: #pragma message: TRUE is Not Defined

Interesting. The preprecessor doesn't care about enums...

I have libraries with conditional compiles like :


// in config.h
#define USE_FEATURE_FOO TRUE

// in some other file
#if USE_FEATURE_FOO
.. implement foo ..
#endif


This does not work if lpc_types is included...

Fix is to edit lpc_types.h and replace the typedef with the usual :

#define FALSE 0
#define TRUE  1

Outcomes