How to get function declaration source file/line from definition?

Fri Jan 22 03:00:00 GMT 2016

Hi Manuel. Thank you for the response. Perhaps your answer is the definitive:

Manuel López-Ibáñez wrote
> My understanding is that once the definition is parsed, it overrides the
> old 
> declaration (they get merged).

I'm still missing something though:

> But of course the old declaration exists at least until this point:
> test.c:3:22: error: new declaration ‘int Something()’
>   static int Something() { }
>                        ^
> test.c:2:13: error: ambiguates old declaration ‘void Something()’
>   static void Something();
>               ^
> Just set a breakpoint there and you'll see. Whether it remains accessible
> or
> not, I don't know. It all depends what you are trying to do. 

My understanding is with a gcc plugin, by the time I get to analyze the AST
the entire source file has been parsed. Therefore, I don't understand how I
could access the old declaration before the merge (maybe that was your final
answer). Also, the example you show has a different signature between
declaration and definition where the former returns 'void' and the latter
returns 'int'. Or when you say 'set a breakpoint', are you using the
different return value to effectively accomplish this? Sorry if you are
speaking high level and I'm not keeping up- please bear with me :)

I should modify my original question just slightly. It's not that I
necessarily need the declaration line number somehow from the definition.
Rather, I would like to get the declaration line number when the current
translation unit contains both.

Further guidance is appreciated. Thanks again.

View this message in context:
Sent from the gcc - Help mailing list archive at

More information about the Gcc-help mailing list