This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Can conditional compilation test strings?
- From: Amit Choudhary <amit2030 at yahoo dot com>
- To: Gre7g Luterman <gre7g-d-1159839347 dot 7f997a at kyoht dot com>, gcc-help at gcc dot gnu dot org
- Date: Wed, 27 Sep 2006 22:03:14 -0700 (PDT)
- Subject: 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