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

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: assert
  5. Message-ID: <1992Dec21.163006.8068@taumet.com>
  6. Organization: TauMetric Corporation
  7. References: <HBF.92Dec19163113@gandalf.uio.no>
  8. Date: Mon, 21 Dec 1992 16:30:06 GMT
  9. Lines: 33
  10.  
  11. hbf@gandalf.uio.no (Hallvard B Furuseth) writes:
  12.  
  13. >assert is sometimes (ie sun or gcc) defined to call another macro (ie
  14. >__assert) which does most or all of the work.  I expect it's a hack to
  15. >make sure the argument is stringified properly, or something like that.
  16. >Can somebody explain?
  17. >--
  18.  
  19. It is probably invoking a function rather than another macro.
  20.  
  21. "assert" has to print output on standard error, generally formatted
  22. in some nice way including the file and line number where the
  23. insertion failed as well as the failed assertion.  The easiest way
  24. to do that is with fprintf().
  25.  
  26. That in turn would mean that the assert header would have to include
  27. <stdio.h> to get the proper declarations, or duplicate the relevent
  28. declarations from <stdio.h>.
  29.  
  30. The first alternative (#include <stdio.h>) is forbidden by the C
  31. Standard (standard headers may not #include other standard headers).
  32.  
  33. The second is messy, and may cause interactions with user code.
  34. (It would impinge on your right to use identifiers from <stdio.h>
  35. when you don't include <stdio.h> in your code.)
  36.  
  37. Probably the best solution is for the assert macro to call a function
  38. which is compiled separately and can therefore include whatever headers
  39. it needs.  This function is often called something like __assert() or
  40. __gripe(), names which are reserved for the implementation.
  41. -- 
  42.  
  43. Steve Clamage, TauMetric Corp, steve@taumet.com
  44.