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

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!mcsun!sunic!aun.uninett.no!nuug!ifi.uio.no!nntp.uio.no!hbf
  3. From: hbf@durin.uio.no (Hallvard B Furuseth)
  4. Subject: Re: assert
  5. In-Reply-To: steve@taumet.com's message of Mon, 21 Dec 1992 16:30:06 GMT
  6. Message-ID: <HBF.92Dec21193832@durin.uio.no>
  7. Sender: news@ulrik.uio.no (Mr News)
  8. Nntp-Posting-Host: durin.uio.no
  9. Organization: University of Oslo, Norway
  10. References: <HBF.92Dec19163113@gandalf.uio.no> <1992Dec21.163006.8068@taumet.com>
  11. Date: Mon, 21 Dec 1992 18:38:32 GMT
  12. Lines: 29
  13.  
  14. In article <1992Dec21.163006.8068@taumet.com> steve@taumet.com (Steve Clamage) writes:
  15.  
  16. >>assert is sometimes (ie sun or gcc) defined to call another macro (ie
  17. >>__assert) which does most or all of the work.  I expect it's a hack to
  18. >>make sure the argument is stringified properly, or something like that.
  19. >>Can somebody explain?
  20. >--
  21. >
  22. > It is probably invoking a function rather than another macro.
  23.  
  24. Yes, then I would understand.  But look at this, from sun4os4.1:
  25.  
  26. # define _assert(ex)    {if (!(ex)){(void)fprintf(stderr,"Assertion failed: file \"%s\", line %d\n", __FILE__, __LINE__);exit(1);}}
  27. # define assert(ex)    _assert(ex)
  28.  
  29. Or this, from gcc-2.3.2/assert.h (this is the __GNUC__ && !__STDC__
  30. part, the other parts are similar):
  31.  
  32. extern void __eprintf (); /* Defined in libgcc.a */
  33.  
  34. #define assert(expression)  \
  35.   ((void) ((expression) ? 0 : __assert (expression, __FILE__, __LINE__)))
  36.  
  37. #define __assert(expression, file, lineno)  \
  38.   (__eprintf ("%s:%u: failed assertion `%s'\n",        \
  39.           file, lineno, "expression"), 0)
  40. --
  41.  
  42. Hallvard
  43.