Searching \ for '[PIC]: A C preprocessor question' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/microchip/languages.htm?key=c
Search entire site for: 'A C preprocessor question'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: A C preprocessor question'
2001\04\01@160107 by Andrew E. Kalman

flavicon
face
I'm wondering how / if you can do the following with symbols in the C
preprocessor:

I'd like to be able to write something like:

       #if CONFIG == c
       ...
       #elif CONFIG == d
       ...
       #endif

so that I can set CONFIG to the letter c or d when invoking a compiler, e.g.

       picc -G -O -Zg5 -D24 -E -ASMLIST-16C77 -C -DCONFIG=c main.c

I know I can do this with numbers, but is there a way I can do it
with non-numeric constants?

I suspect it's not possible, but thought I'd ask ...

Thanks,
--

 ______________________________________
  Andrew E. Kalman, Ph.D.   spam_OUTaekTakeThisOuTspampumpkininc.com

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam@spam@mitvma.mit.edu


2001\04\01@165911 by Bob Ammerman

picon face
Of course its possible:

Try this:

#define c == 1
#define d == 2

#if CONFIG == c
...
#elif CONFIG == d
...
#endif


Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)

{Original Message removed}

2001\04\01@171637 by Andrew E. Kalman

flavicon
face
Re:

>Try this:
>
>#define c == 1
>#define d == 2
>
>#if CONFIG == c
>...
>#elif CONFIG == d
>...
>#endif


I presume you meant

#define c 1
#define d 2
...

Yes, that works inside of files, but I need to define the symbol
_outside_ of any file, e.g. on the compiler's command-line. I don't
want to involve any other files ("include on demand") that would
contain the #define directive. This is a subtle difference ...
--

 ______________________________________
  Andrew E. Kalman, Ph.D.   aekspamKILLspampumpkininc.com

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam.....mitvma.mit.edu


2001\04\01@172438 by Bob Ammerman

picon face
> #define c 1
> #define d 2

Yeah, that's what I meant.

>
> Yes, that works inside of files, but I need to define the symbol
> _outside_ of any file, e.g. on the compiler's command-line. I don't
> want to involve any other files ("include on demand") that would
> contain the #define directive. This is a subtle difference ...

inside your file:

#define c 1
#define d 2

#if CONFIG == c
 ...
#elif CONFIG == d

#endif

And all that has to go on the command line is:

   -dCONFIG=c

which is, I believe, what you are looking for.

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)

--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspam_OUTspamTakeThisOuTmitvma.mit.edu


2001\04\01@182809 by Andrew E. Kalman

flavicon
face
{Quote hidden}

Ahhh .. so we give the char a numeric value via the #define, so that
a valid comparison can be made, and we can pass any character in on
the command line.

Thanks, that's what I was looking for!
--

 ______________________________________
  Andrew E. Kalman, Ph.D.   aekspamspam_OUTpumpkininc.com

--
http://www.piclist.com hint: To leave the PICList
@spam@piclist-unsubscribe-requestKILLspamspammitvma.mit.edu


2001\04\01@215908 by Bill Westfield

face picon face
> Yes, that works inside of files, but I need to define the symbol
> _outside_ of any file, e.g. on the compiler's command-line.

You mean rather like the -D option described below?  Every c compiler
I've used supports it, along with make/etc....

BillW


NAME
    cpp - the C language preprocessor

SYNOPSIS
    /usr/ccs/lib/cpp [ -BCHMpPRT ] [ -undef ] [ -Dname ]
         [ -Dname=def ] [ -Idirectory ] [ -Uname ]
         [ -Ydirectory ] [ input-file [ output-file ] ]

       :

    -Dname         Define name as 1 (one). This is the  same  as
                   if a -Dname=1 option appeared on the cpp com-
                   mand line, or as if a

                        #define name 1

                   line appeared in the source file that cpp  is
                   processing.

    -Dname=def     Define name as if  by  a  #define  directive.
                   This is the same as if a

                        #define name def

                   line appeared in the source file that cpp  is
                   processing.   The  -D  option  has lower pre-
                   cedence than the -U option.  That is, if  the
                   same  name  is used in both a -U option and a
                   -D option, the name will be undefined regard-
                   less of the order of the options.

--
http://www.piclist.com hint: To leave the PICList
KILLspampiclist-unsubscribe-requestKILLspamspammitvma.mit.edu


2001\04\01@231751 by Andrew E. Kalman

flavicon
face
Re:

>  > Yes, that works inside of files, but I need to define the symbol
>>  _outside_ of any file, e.g. on the compiler's command-line.
>
>You mean rather like the -D option described below?  Every c compiler
>I've used supports it, along with make/etc....

Right - the problem I had was that I was passing

       -Dsymbol=c

on the command line, and then doing a comparison like this:

       #if symbol == c

which doesn't work and causes strange behavior (it seems to behave
like #ifdef instead), all because c must be of integer value, which I
was failing to give it. The cure, which I figured out and Bob
Ammerman suggested simultaneously, is to simply give c an integer
value, like:

       #define c 1

inside the file where the comparison is made, prior to the comparison.

Regards,
--

 ______________________________________
  Andrew E. Kalman, Ph.D.   RemoveMEaekTakeThisOuTspampumpkininc.com

--
http://www.piclist.com hint: To leave the PICList
spamBeGonepiclist-unsubscribe-requestspamBeGonespammitvma.mit.edu


More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...