Re: Can conditional compilation test strings?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



See inline..

--- Gre7g Luterman <gre7g-d-1159839347.7f997a@xxxxxxxxx> 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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux