Can conditional compilation test strings?

Gre7g Luterman
Thu Sep 28 01:35:00 GMT 2006

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 

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:


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 

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!

More information about the Gcc-help mailing list