public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Hiroki Kaminaga <kaminaga@sm.sony.co.jp>
To: gcc-help@gcc.gnu.org
Subject: #line directive and -D option
Date: Tue, 16 Dec 2008 06:11:00 -0000	[thread overview]
Message-ID: <20081216.151100.68033879.kaminaga@sm.sony.co.jp> (raw)


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
--

             reply	other threads:[~2008-12-16  6:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-16  6:11 Hiroki Kaminaga [this message]
2008-12-16 12:45 ` John (Eljay) Love-Jensen
2008-12-17  2:39   ` Hiroki Kaminaga
2008-12-17  2:40     ` Jan Engelhardt
2008-12-17  3:24     ` John (Eljay) Love-Jensen
2008-12-17  3:55       ` Jan Engelhardt
2008-12-17 17:47         ` Hiroki Kaminaga

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081216.151100.68033879.kaminaga@sm.sony.co.jp \
    --to=kaminaga@sm.sony.co.jp \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).