From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17796 invoked by alias); 16 Dec 2008 06:11:52 -0000 Received: (qmail 17788 invoked by uid 22791); 16 Dec 2008 06:11:52 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from ms6.Sony.CO.JP (HELO ms6.sony.co.jp) (211.125.136.204) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 16 Dec 2008 06:11:04 +0000 Received: from mta6.sony.co.jp (mta6.Sony.CO.JP [137.153.71.9]) by ms6.sony.co.jp (R8/Sony) with ESMTP id mBG6B0GZ009011 for ; Tue, 16 Dec 2008 15:11:00 +0900 (JST) Received: from mta6.sony.co.jp (localhost [127.0.0.1]) by mta6.sony.co.jp (R8/Sony) with ESMTP id mBG6B0Nb024081 for ; Tue, 16 Dec 2008 15:11:00 +0900 (JST) Received: from smail1.sm.sony.co.jp (smail1.sm.sony.co.jp [43.11.253.1]) by mta6.sony.co.jp (R8/Sony) with ESMTP id mBG6B0GW024076 for ; Tue, 16 Dec 2008 15:11:00 +0900 (JST) Received: from imail.sm.sony.co.jp (imail.sm.sony.co.jp [43.4.141.32]) by smail1.sm.sony.co.jp (8.11.6p2/8.11.6) with ESMTP id mBG6B0205954 for ; Tue, 16 Dec 2008 15:11:00 +0900 (JST) Received: from localhost (tidal.sm.sony.co.jp [43.4.145.112]) by imail.sm.sony.co.jp (8.12.11/3.7W) with ESMTP id mBG6AlCY022736 for ; Tue, 16 Dec 2008 15:10:47 +0900 (JST) Date: Tue, 16 Dec 2008 06:11:00 -0000 Message-Id: <20081216.151100.68033879.kaminaga@sm.sony.co.jp> To: gcc-help@gcc.gnu.org Subject: #line directive and -D option From: Hiroki Kaminaga Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2008-12/txt/msg00177.txt.bz2 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 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 --