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