home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11797 < prev    next >
Encoding:
Internet Message Format  |  1992-07-30  |  2.0 KB

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