home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / gnu / gcc / bug / 3056 < prev    next >
Encoding:
Text File  |  1992-12-25  |  2.0 KB  |  60 lines

  1. Newsgroups: gnu.gcc.bug
  2. Path: sparky!uunet!cis.ohio-state.edu!delilah.ccsf.caltech.edu!johns
  3. From: johns@delilah.ccsf.caltech.edu (John Salmon)
  4. Subject: varargs macros
  5. Message-ID: <JOHNS.92Dec24103027@delilah.ccsf.caltech.edu>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: Caltech Concurrent Supercomputing Facility.
  8. Distribution: gnu
  9. Date: Thu, 24 Dec 1992 15:30:27 GMT
  10. Approved: bug-gcc@prep.ai.mit.edu
  11. Lines: 47
  12.  
  13. I'm not sure if this is a bug or a misunderstanding.  I am trying to
  14. write a varargs macro 'Error', which adds __FILE__ and __LINE__
  15. information to a printf-like argument list.  It works fine, except
  16. when the "rest" argument is empty, in which case the ##rest
  17. consrtuction deletes too much of the preceding text.  I expected the
  18. ##args construction to delete only the preceding comma, but instead,
  19. it deletes the __LINE__ as well as the comma.  
  20.  
  21. Is this the "correct" behavior?  Is there a reason why the ##rest
  22. construction should delete more than the previous comma?  Is there a
  23. workaround?
  24.  
  25. Thanks,
  26. John Salmon         Internet: johns@delilah.ccsf.caltech.edu
  27. 206-49 Caltech         UUCP: johns%delilah.ccsf.caltech.edu@uunet.uu.net
  28. Pasadena, CA 91125 USA     Bitnet: johns@caltech.bitnet
  29. (818)356-2907         delilah.ccsf.caltech.edu=[131.215.145.137]
  30.  
  31. delilah->cat junk.c
  32. void volatile _Error(const char *, ...) 
  33.      __attribute__ ((format (printf, 1, 2)));
  34. #define Error(format, args...) \
  35.     _Error(__FILE__ "(%d):" format, __LINE__ , ##args)
  36.  
  37. main(){
  38.     Error("hello world");
  39.     Error("Hello %s", "world");
  40. }
  41. delilah->gcc -E junk.c
  42. # 1 "junk.c"
  43. void volatile _Error(const char *, ...) 
  44.      __attribute__ ((format (printf, 1, 2)));
  45.  
  46.  
  47.  
  48. main(){
  49.     _Error("junk.c" "(%d):" "hello world") ;
  50.     _Error("junk.c" "(%d):" "Hello %s", 8 ,"world") ;
  51. }
  52. delilah->
  53.  
  54. --
  55. John Salmon         Internet: johns@delilah.ccsf.caltech.edu
  56. 206-49 Caltech         UUCP: johns%delilah.ccsf.caltech.edu@uunet.uu.net
  57. Pasadena, CA 91125 USA     Bitnet: johns@caltech.bitnet
  58. (818)356-2907         delilah.ccsf.caltech.edu=[131.215.145.137]
  59.  
  60.