help-bison
[Top][All Lists]
Advanced

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

Re: #line format


From: Hans Aberg
Subject: Re: #line format
Date: Wed, 10 Apr 2002 23:44:13 +0200

At 19:52 +0200 2002/04/10, Akim Demaille wrote:
>I have a simple question: what are the formats for #lines?  For some
>time, I have believed that:
>
>
>---------- foo.c ---------
>
>#line 1 "foo.y"
>#error "This is reported in line 1 of foo.y"
>#line 45
>#error "This is reported in line 45 of foo.c"
>
>-------------------------
>
>But it turns out that GCC, seeing a plain `#line NUM' with no FILE
>complains in the current file, i.e., here, foo.y.
>
>I have seen many different formats for #line, in particular GCC's has
>many more fields, related to file inclusion I guess.

The book by Stroustrup, "The C++ PL", says that
  #line <constant> "<file-name>"
sets __FILE__ to <file-name>, whereas
  #line <constant>
does not change the __FILE__ registered. So GCC is correct.

Harbison & Steele says the same thing, but adds that one can use
preprocessor tokens after #line.

>My problem with
>
>        #line 45 "foo.c"
>
>is that the name of the file is coded inside, which is very painful
>when you mv the file.  I'm especially concerned by this because of
>Automake which invokes bison as yacc, therefore foo.tab.c is created,
>and then renamed as `foo.c'.  This results in a wrong #line.  I have
>patched Automake so that it seds the proper name, but that remains a
>hack.
>
>Is there something available in the set of #line that would comply
>these requirements?

So the only thing I can think of is that you write

#ifndef
#define this_file "this_file.c"
#endif

...

#line 45 this_file

Then, if the name of this file is changed, one has to supply the macro
this_file before the compilation if one wnats the error messages right.

>PS/ I could not find any relevant information on the web, nor info
>cpp, info gcc and so forth.

In the C++ standard ISO+IEC+14882-1998, its in 16.4, "Line Control".

  Hans Aberg





reply via email to

[Prev in Thread] Current Thread [Next in Thread]