Re: can #line directive dynamically resolve the file path?

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

 



On 2010-12-26 11:17, Jeffrey Walton wrote:
On Sat, Dec 25, 2010 at 10:00 PM, asmwarrior<asmwarrior@xxxxxxxxx>  wrote:
Hi, I have a question about #line directive. I have two files. a.c and b.c
under my c:/ (I use Windows MinGW)

Now, I have a.c
---------------------------------------------
int main()
{
  #line 1 "b.c"
  int a
  return 0;
}
---------------------------------------------
and b.c
---------------------------------------------
int f1()
{
  return 0;
}
---------------------------------------------


Now, I try to run the command line:

C:\>gcc -c C:\a.c
b.c: In function 'main':
b.c:2:3: error: expected '=', ',', ';', 'asm' or '__attribute__' before
'return'
C:\>

You can see, the gcc report error says there are some error in "b.c" but not
"c:\b.c".
which means gcc can not dynamically resolve the file path after the #line
directive.

Though I can hard-coded the "c:/b.c" to the a.c file, but this is not a good
solution because I would always move the code to other place.

My question is: Can any one give me an idea to solve this kind of problem?
thanks.


One reference is:
http://gcc.gnu.org/onlinedocs/cpp/Line-Control.html#Line-Control
Writing a parser generator?
Thanks for your reply!!

Correct, in-fact, I'm using QUEX lexical lexer generator:
https://sourceforge.net/projects/quex/

And my question comes the case that I would like to distribute the generated lexer code with the Quex code base. But the lexer code contains a lot of #line directive which reference to Quex code base.

see the discussion here:
https://sourceforge.net/projects/quex/forums/forum/574343/topic/4001340?message=8948936

Try __LINE__ and __FILE__ instead.
http://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html

Jeff
Did you mean that I just do some thing like this?

instead of write

#line 1 "c:/b.c"

I need to write like:

#define __LINE__ "c:/b.c"
#define __LINE__ 1

Am I right?

thanks

asmwarrior


[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