Re: inconsistent macro behavior

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

 



Reza Roboubi skrev:
Hi,

this is the test file:

$ cat test.c
#define x "llll
#define y "
char * c =3D x y ;

Now, if I do this:
$ gcc -Wall -E test.c
It works as expected, and produces preprocessed output that is
perfectly compilable.

But, if I do this:
$ gcc -Wall -c test.c -o test.o
Then I get this:
test.c:3: error: missing terminating " character
test.c:3: error: missing terminating " character
test.c:3: error: expected expression before =91;=92 token

The questions are:
a.)  What's even going on here?  Why the apparent inconsistency?
b.)  What _should_ be the correct behavior, both in terms of the
(extended) GNU C language, and also the standard C language?

Thanks so much for your help.

Reza.


I believe that each c-style string must be encapsulated with " even for the preprocessor to work. Actually, at least gcc-4.3 emits warnings about missing termination for both line 1 and 2 in your test case.

Perhaps you could work something out with the ## concatenation operator?
--


//*David Sveningsson [eXt]*

Freelance coder | Game Development Student
http://sidvind.com

Thou shalt make thy program's purpose and structure clear to thy fellow man by using the One True Brace Style, even if thou likest it not, for thy creativity is better used in solving problems than in creating beautiful new impediments to understanding.

Attachment: signature.asc
Description: OpenPGP digital signature


[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