can #line directive dynamically resolve the file path?

Jonathan Wakely jwakely.gcc@gmail.com
Sun Dec 26 16:38:00 GMT 2010


On 26 December 2010 03:00, asmwarrior 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.

Why should it try to resolve anything?  The filename given to #line is
simply a string constant.

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

What exactly is the problem?  What are you trying to achieve with the
#line directive?



More information about the Gcc-help mailing list