Subject: re: C Hacker question - thanks!

From: Joe Leonard <[email-masked]>
Date: Thu, 04 Jul 2002 11:47:03 -0400

Thanks to all who replied to my question regarding how to get the
name of the calling routine of a C function.  It seems this is not "a
simple thing", which is what I was afraid of.  The most useful suggestion(s)
were to treat the problem via #defining the call rather than have the
routine figure out its caller:

#define Error_Msg(x,y)     Error_Msg_Linux(__func__,x,y)

so that one could write

Error_Msg("Unable to open output file",UNABLE_TO_OPEN)

and the error message routine would see the calling function as the first
argument.  __FUNCTION__ seems to work as well in gcc, although
__func__  conforms to the newer standard.  This makes it easy for error
messages to be tagged where they arise (which is what I was looking
for).

Research is currently underway on SGI - the older machines I have access
to don't see to have either of these symbols.  I'm making due with __FILE__
and __LINE__, which is not quite what I want (but it works).  If anybody's
familiar with a similar variable (or compiler switch setting) for IRIX C to get
me what gcc yields, please post it!

I want to keep using IRIX C as long as possible due to the performance gains
which result.

Thanks again to all - hopefully this helps somebody else with how to do
nice error messages!

Joe Leonard
[email-masked] (formerly [email-masked])