Can conditional compilation test strings?

Amit Choudhary amit2030@yahoo.com
Thu Sep 28 05:03:00 GMT 2006


See inline..

--- Gre7g Luterman <gre7g-d-1159839347.7f997a@kyoht.com> 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

#include<stdio.h>

#define XYZ_123 123

main()
{
#if MODEL_NUMBER==XYZ_123
    char *z = "I got XYZ_123";
#endif

    char *p = MODEL_STRING;

#if MODEL_NUMBER!=XYZ_123
    char *z = "I DID NOT get XYZ_123";
#endif

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

Hope this helps.

Regards,
Amit


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Gcc-help mailing list