home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11791 < prev    next >
Encoding:
Text File  |  1992-07-30  |  1.8 KB  |  57 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!sun-barr!ames!elroy.jpl.nasa.gov!usc!sol.ctr.columbia.edu!The-Star.honeywell.com!umn.edu!ulysses.cs.umn.edu!kencham
  3. From: kencham@ulysses.cs.umn.edu (Deepak)
  4. Subject: Function name : C preprocessor question
  5. Message-ID: <1992Jul30.224332.3277@news2.cis.umn.edu>
  6. Followup-To: comp.lang.c
  7. Sender: news@news2.cis.umn.edu (Usenet News Administration)
  8. Nntp-Posting-Host: ulysses.cs.umn.edu
  9. Organization: University of Minnesota
  10. Date: Thu, 30 Jul 1992 22:43:32 GMT
  11. Lines: 44
  12.  
  13. O, C-gurus !!
  14.  
  15. I was wondering if there was anyway to get the name of function that is being currently executed. The scenario is as follows : 
  16.  
  17. Suppose you have a debugging macro that is defined as follows :
  18.  
  19. #define DEBUGSTR(x)  fprintf(stderr , "In File : %s , Function :%s error : %s"\
  20.             __FILE__ , <GOD-KNOWS-WHAT> , x )
  21.  
  22. and somewhere in file foobar.c I have the following code :
  23.  
  24. ....
  25. ...
  26. .
  27. foobarfunction(foobarvar)
  28. foobarstruct foobarvar;
  29. {
  30. int foo;
  31.  
  32.     if ( foobarvar == 0 ) DEBUGSTR("foobarvar was zero");
  33.     blah !
  34.     blah !!
  35.     blah !!
  36. }
  37. .
  38. ..
  39. ...
  40.  
  41. The result should be that if foobarvar happened to be 0 then the following should be printed on stderr.
  42.  
  43. In File : foobar.c , Function :foobarfunction error : foobarvar was zero
  44.  
  45. Is it possible to do this using the preprocessor without passing the name of the function as an additional argument to the macro ?
  46.  
  47. Silly question ,eh ?
  48.  
  49. Deepak
  50. -- 
  51. ********************************************************************************
  52. *  Deepak R. Kenchammana-Hosekote                    *******     ******     *
  53. *  Dept. of CSci, University of Minnesota             ***  *** *** ***      *
  54. *  1:((612) 626-8396(o),(612) 339-8997(r))              ***   *****  ***      *
  55. *  kencham@ulysses.cs.umn.edu                        *****        *****     *
  56. ********************************************************************************
  57.