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]

Re: Can conditional compilation test strings?


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 


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