Can conditional compilation test strings?

Amit Choudhary
Thu Sep 28 05:03:00 GMT 2006

See inline..

--- Gre7g Luterman <> wrote:

> 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

Why not use two, one to assign and other to compare.

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

 and in your program you can do both:

 const char *ModelString=MODEL_STRING;
 #if MODEL_NUMBER==123


#define XYZ_123 123

    char *z = "I got XYZ_123";

    char *p = MODEL_STRING;

    char *z = "I DID NOT get XYZ_123";

    printf("%s, %s\n", z, p);

Hope this helps.


Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 

More information about the Gcc-help mailing list