home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!cs.utexas.edu!asuvax!ncar!noao!amethyst!organpipe.uug.arizona.edu!news
- From: dave@cs.arizona.edu (Dave Schaumann)
- Newsgroups: comp.lang.c
- Subject: Re: Function name : C preprocessor question
- Message-ID: <1992Jul31.041203.8539@organpipe.uug.arizona.edu>
- Date: 31 Jul 92 04:12:03 GMT
- References: <1992Jul30.224332.3277@news2.cis.umn.edu>
- Sender: news@organpipe.uug.arizona.edu
- Reply-To: dave@cs.arizona.edu (Dave Schaumann)
- Organization: University of Arizona
- Lines: 30
- In-Reply-To: kencham@ulysses.cs.umn.edu (Deepak)
-
- In article <1992Jul30.224332.3277@news2.cis.umn.edu>, kencham@ulysses (Deepak) writes:
- >I was wondering if there was anyway to get the name of function that is
- >being currently executed. The scenario is as follows :
- >
- >Suppose you have a debugging macro that is defined as follows :
- >
- >#define DEBUGSTR(x) fprintf(stderr , "In File : %s , Function :%s error : %s"\
- > __FILE__ , <GOD-KNOWS-WHAT> , x )
- >
-
- The short answer is this can't be done. The C standard defines the
- process of compiling so that macro processing phase can run completely
- independantly from the parsing phase. Since there is no way to know
- a function name before parsing begins, there is no way a conforming
- compiler can have a __FUNCTION__ macro as you describe above.
-
- That said, it wouldn't be difficult to write a C compiler that /could/
- define such a macro, and in fact, at least one (GNU's gcc) provides
- just such an extension.
-
- If you have this feature available to you, and you don't care much about
- portability, go ahead and use it. In my experience, though, the __FILE__
- and __LINE__ macros are suitable for a debugging log unless you are
- creating log entries from a lot of different points in your file.
-
- --
- You unlock this door with the key of imagination. Beyond it is another
- dimension: a dimension if sound, a dimension of sight, a dimension of mind.
- You're moving into a land of both shadow and substance, of things and ideas.
- You've just crossed over into... the Twilight Zone.
-