home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / c / 18785 < prev    next >
Encoding:
Text File  |  1992-12-22  |  1.6 KB  |  47 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!gatech!usenet.ins.cwru.edu!agate!spool.mu.edu!umn.edu!math.fu-berlin.de!news.th-darmstadt.de!rbg.informatik.th-darmstadt.de!misar
  3. From: misar@rbg.informatik.th-darmstadt.de (walter misar)
  4. Subject: Re: assert
  5. Sender: news@news.th-darmstadt.de (The News System)
  6. Message-ID: <1992Dec22.171004@rbg.informatik.th-darmstadt.de>
  7. Date: Tue, 22 Dec 1992 16:10:04 GMT
  8. References:  <HBF.92Dec19163113@gandalf.uio.no>
  9. Nntp-Posting-Host: rbhp58.rbg.informatik.th-darmstadt.de
  10. Organization: TH Darmstadt
  11. Lines: 34
  12.  
  13. In article <HBF.92Dec19163113@gandalf.uio.no>, hbf@gandalf.uio.no (Hallvard B Furuseth) writes:
  14. > assert is sometimes (ie sun or gcc) defined to call another macro (ie
  15. > __assert) which does most or all of the work.  I expect it's a hack to
  16. > make sure the argument is stringified properly, or something like that.
  17. > Can somebody explain?
  18.  
  19. Shrug. But at looking on sun's definition of assert() if found following (bug ?):
  20.  
  21. #define _assert(ex)    {if (!(ex)){(void)fprintf(stderr,"Assertion failed: file
  22.  \"%s\", line %d\n", __FILE__, __LINE__);exit(1);}}
  23. #define assert(ex)     _assert(ex)
  24.  
  25. This wont work in cases like this
  26.  
  27. #include <stdio.h>
  28. #include <assert.h>
  29.  
  30. main()
  31. { if (42==42) assert(17<23);
  32.   else printf("never");
  33. }
  34.  
  35. =>
  36.  
  37. $cc t.c
  38. "t.c", line 6: syntax error at or near word "else"
  39.  
  40. cause it expands to something like this if (...) {...}; else ....
  41. (Gnu does it right, using a ? : instead of the if, thus having no need
  42.  for the {})
  43.  
  44. -- 
  45. Walter Misar                        It is impossible to enjoy idling thoroughly
  46. misar@rbg.informatik.th-darmstadt.de       unless one has plenty of work to do.
  47.