Page 1 of 1

GCC preprocessor and assembler files

Posted: Tue Aug 11, 2020 4:23 pm
by steved
Not specifically ChibiOS but I've encountered a very odd situation with preprocessor directives that maybe someone else has seen.

Symbol _USE_CHIBI_20 is passed via the command line from the makefile.

At the top of chconf.h I have the following:

Code: Select all

#define XSTR(x) STR(x)
#define STR(x) #x
#pragma message "Chibi 20 state: " XSTR(_USE_CHIBI_20)

#if defined(_USE_CHIBI_20)
#define _CHIBIOS_RT_CONF_
#define _CHIBIOS_RT_CONF_VER_6_1_
#pragma message "Compiling for Chibi 20"
#endif


chconf.h is included into chcoreasm_v7m.S, which aborts compilation with an "invalid chconf.h" error
The #pragma message duly prints a value of 1; however the #if defined() is clearly evaluating to false.
(I have tried #ifdef _USE_CHIBI_20 and #if _USE_CHIBI_20 > 0 as well)

If I change the test to the following, everything compiles:

Code: Select all

#if defined(_USE_CHIBI_20) || defined(_FROM_ASM_)

(_FROM_ASM_ is defined in chcoreasm_v7m.S)

It seems to be odd behaviour of the defined() preprocessor directive when included from assembler. (I have tried various other combinations as well)

Has anyone come across something like this before?