This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Can conditional compilation test strings?


I'm writing a C program to be embedded in some new hardware.  The 
model string is passed in with a gcc command-line parameter:

gcc source.c -DMODEL_STRING='"XYZ-123"' -o source.o

Yes, the quotes are kind of annoying, but it makes it easy for me to 
do:

const char *ModelString=MODEL_STRING;

Anyhow, I'd like to compile in certain parameters based on the model 
string.  I know if the model was a number, I could do something like:

#if MODEL_NUMBER==123

But is there a way to compare a string?  I tried to do

#if MODEL_STRING=="\"XYZ-123\""

But that gave me the following error:

source.c:20:22: token ""\"XYZ-123\""" is not valid in preprocessor 
expressions

Is there a way to do this?  Is there a better way to do this than the 
simplistic method I've chosen?  Is there a page out there on the web 
somewhere with some hints for hacks like this?

Thanks in advance!
Gre7g


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]