#line directive and -D option

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

 



Hi,

When #line directive and -D NAME=DEFINITION is used togather, I get
a compile error. Below is what I tried:

$ cat macro-test.c 
#if !defined(MYNAME)
#define MYNAME __FILE__
#endif
#line 5 MYNAME
#include <stdio.h>
int main(void)
{
  printf ("%s: .... \n", __FILE__);
  return 0;
}

$ cat Makefile 
CROSS=
CC=$(CROSS)gcc
all: 
	$(CC) $(shell pwd)/macro-test.c -o macro-test
	$(CC) $(shell pwd)/macro-test.c -o macro-test2 -D MYNAME="macrotest"

$ make
gcc /home/kaminaga/tmp/dir/macro-test.c -o macro-test
gcc /home/kaminaga/tmp/dir/macro-test.c -o macro-test2 -D MYNAME="macrotest"
/home/kaminaga/tmp/dir/macro-test.c:4:9: "macrotest" is not a valid filename
make: *** [all] Error 1

I'm using (old) FC3 gcc version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3).
I get same result on CentOS 5 gcc version 4.1.2 20070626 (Red Hat 4.1.2-14)


>From gcc info, -D option states

`-D NAME=DEFINITION'
     The contents of DEFINITION are tokenized and processed as if they
     appeared during translation phase three in a `#define' directive.
     In particular, the definition will be truncated by embedded
     newline characters.

I don't know much about above "translation phase three", and when #line
is processed, so is this a bug or GCC constraint?


Thanks in Advance,

(Hiroki Kaminaga)
t
--

[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