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

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

 



On 22/01/16 00:13, crasypantz wrote:
When iterating the AST in these cases I only find one 'FUNCTION_DECL' tree
node for 'Something' where 'DECL_SOURCE_LINE' returns the definition
location. I would like to also get the location of the declaration. The
header information for 'DECL_SOURCE_LINE' in 'tree.h' states, "If the
declaration appears in several places (as for a C function that is declared
first and then defined later), this information should refer to the
definition." But what I do not understand if it is therefore impossible to
get the source line of the declaration altogether. Is there another tree
node accessible pertaining to the declaration? Is there some other means? I
searched the archive and did not find an answer to my situation. Any help is
appreciated.

My understanding is that once the definition is parsed, it overrides the old declaration (they get merged). 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.

Cheers,

Manuel.



[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