public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug preprocessor/41540]  New: -dM -E doesn't #define __FILE__
@ 2009-10-01 22:08 msebor at gmail dot com
  2009-10-02 16:21 ` [Bug preprocessor/41540] " pinskia at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: msebor at gmail dot com @ 2009-10-01 22:08 UTC (permalink / raw)
  To: gcc-bugs

The documentation for the -dM -E option states that

  "Instead of the normal output, generate a list of `#define' directives for
  all the macros defined during the execution of the preprocessor, including
  predefined macros. This gives you a way of finding out what is predefined
  in your version of the preprocessor."

but the predefined standard macro __FILE__ does not appear in the output
(and neither does __LINE__):

$ echo >t.c && gcc -dM -E t.c | grep __FILE__ || echo "__FILE__ not #defined"
__FILE__ not #defined
$ 

I believe __FILE__ should always appear in the output.

Since __LINE__ changes its value from line to line it should either be
documented as not being output at all or, perhaps preferably, it should
be output with the value of 0.


-- 
           Summary: -dM -E doesn't #define __FILE__
           Product: gcc
           Version: 4.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: preprocessor
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: msebor at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41540


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug preprocessor/41540] -dM -E doesn't #define __FILE__
  2009-10-01 22:08 [Bug preprocessor/41540] New: -dM -E doesn't #define __FILE__ msebor at gmail dot com
@ 2009-10-02 16:21 ` pinskia at gcc dot gnu dot org
  2009-10-02 16:39 ` msebor at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-10-02 16:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2009-10-02 16:21 -------
__FILE__ is dependent on # markers and #line markers in the preprocessed source
so this is invalid.  __LINE__ is also dependent too.

If you look at the preprocessed source you will notice still some # in there.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41540


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug preprocessor/41540] -dM -E doesn't #define __FILE__
  2009-10-01 22:08 [Bug preprocessor/41540] New: -dM -E doesn't #define __FILE__ msebor at gmail dot com
  2009-10-02 16:21 ` [Bug preprocessor/41540] " pinskia at gcc dot gnu dot org
@ 2009-10-02 16:39 ` msebor at gmail dot com
  2009-10-02 16:57 ` pinskia at gcc dot gnu dot org
  2009-10-02 18:01 ` msebor at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: msebor at gmail dot com @ 2009-10-02 16:39 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from msebor at gmail dot com  2009-10-02 16:39 -------
I don't have a strong objection to not including __FILE__ and the rest of
standard predefined macros (e.g., __LINE__, __DATE__ and __TIME__) in the
output if that's by design but I would expect the documentation to mention
that some macros are deliberately left out. As it stands, it states that
all macros are defined, which is clearly not the case.

I suggest clarifying the documentation by changing the paragraph quoted
above to read:

  "Instead of the normal output, generate a list of `#define' directives for
  the majority of macros defined during the execution of the preprocessor,
  including predefined macros (the standard macros __DATE__, __FILE__,
  __LINE__, and __TIME__ are excluded from this list). This gives you a way
  of finding out what is predefined in your version of the preprocessor."

I'm not familiar with the process for updating gcc docs but if you point me
in the right direction I would be happy to submit a patch.


-- 

msebor at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41540


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug preprocessor/41540] -dM -E doesn't #define __FILE__
  2009-10-01 22:08 [Bug preprocessor/41540] New: -dM -E doesn't #define __FILE__ msebor at gmail dot com
  2009-10-02 16:21 ` [Bug preprocessor/41540] " pinskia at gcc dot gnu dot org
  2009-10-02 16:39 ` msebor at gmail dot com
@ 2009-10-02 16:57 ` pinskia at gcc dot gnu dot org
  2009-10-02 18:01 ` msebor at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-10-02 16:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2009-10-02 16:57 -------
Hmm, considering the C99 standard has a footnote about __FILE__ (149)
149) The presumed source file name and line number can be changed by the #line
directive.


So of course it is hard to define these in the preprocessed source.  I really
don't think there should be a note about these predefined macro names based on
what is mentioned in the standard.  Since they are dependent on the file that
is being compiled (not preprocessed).  


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41540


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug preprocessor/41540] -dM -E doesn't #define __FILE__
  2009-10-01 22:08 [Bug preprocessor/41540] New: -dM -E doesn't #define __FILE__ msebor at gmail dot com
                   ` (2 preceding siblings ...)
  2009-10-02 16:57 ` pinskia at gcc dot gnu dot org
@ 2009-10-02 18:01 ` msebor at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: msebor at gmail dot com @ 2009-10-02 18:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from msebor at gmail dot com  2009-10-02 18:00 -------
I understand that the values of __FILE__ and __LINE__ change within the same
translation unit and thus may not be meaningful in the output of -dM -E. But
the values of __DATE__ and __TIME__ do not change within a translation unit
and so they could and IMO should be included in the output.

In any case, since the preprocessed output contains all the standard macros
expanded, I think it's reasonable to either see them all in the output of
-dM -E or the discrepancies between the two kinds of output to be mentioned
in the docs. I don't insist on including an exhaustive list of all macros
excluded from the output if this list is large or changes depending on
compiler options etc. but I do think that the docs ought to be clarified
so as not to state that *all* macros are output.

Here's a small test program to show the discrepancies:

$ cat u.c && gcc -E u.c && gcc -E -dM u.c | grep -e__DATE__ -e__FILE__
-e__LINE__ -e__STDC__ -e__STDC_HOSTED__ -e__STDC_VERSION__ -e__TIME__
char date[] = __DATE__;
int line = __LINE__;
char file[] = __FILE__;
char time[] = __TIME__;
int stdc = __STDC__;
int stdc_hosted = __STDC_HOSTED__;
# 1 "u.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "u.c"
char date[] = "Oct  2 2009";
int line = 2;
char file[] = "u.c";
char time[] = "11:52:51";
int stdc = 1;
int stdc_hosted = 1;
#define __STDC_HOSTED__ 1
#define __STDC__ 1


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41540


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-10-02 18:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-01 22:08 [Bug preprocessor/41540] New: -dM -E doesn't #define __FILE__ msebor at gmail dot com
2009-10-02 16:21 ` [Bug preprocessor/41540] " pinskia at gcc dot gnu dot org
2009-10-02 16:39 ` msebor at gmail dot com
2009-10-02 16:57 ` pinskia at gcc dot gnu dot org
2009-10-02 18:01 ` msebor at gmail dot com

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