*BSD News Article 22730


Return to BSD News archive

Path: sserve!newshost.anu.edu.au!munnari.oz.au!spool.mu.edu!howland.reston.ans.net!news.ans.net!cmcl2!jpmorgan.com!jpmorgan.com!cae!cae
From: cae@cae.ny.jpmorgan.com (Caleb Epstein)
Newsgroups: comp.unix.bsd
Subject: Re: does a __FUNCTION macro exist?
Date: 22 Oct 1993 20:19:03 GMT
Organization: J.P. Morgan & Co. Incorporated
Lines: 26
Message-ID: <2a9f7n$455@tcpg02.ny.jpmorgan.com>
References: <1993Oct22.154317.16881@almserv.uucp>
NNTP-Posting-Host: cae.ny.jpmorgan.com

sxupjd@anubis (Philip J DiFalco) wrote:
| 
| I have the following statement in my x.h file to help me debug my *.c modules
| 
| #define XDEBUG(fmt,var)	(printf("[%s, line %d] "fmt"\n", \
|                                __FILE__, __LINE__, var))
| 
| Is there a macro, like __FILE__ or __LINE__, that will tell me what function
| or procedure a printf statement occurred in?

	The short answer is no.  If you use gcc, however, you can make
use of the __FUNCTION__ and __PRETTY_FUNCTION__ macros (the latter is
for C++ and gives class information) which are gcc-specific
extensions.

	__FILE__ and __LINE__ are generated by the preprocessor, which
has zero knowledge of functions and most other C constructs, so the
__FUNCTION__ information simply doesn't exist for it to do a macro
substitution.  The GNU folk must have either implemented these two
macros in the compiler proper or they've got a much smarter
preprocessor that knows about function boundaries.

	Hope this helps.

-- 
[ cae@jpmorgan.com ][ Caleb Epstein ][ JP Morgan & Co. Incorporated ][ NY, NY ]