home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- 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
- From: misar@rbg.informatik.th-darmstadt.de (walter misar)
- Subject: Re: assert
- Sender: news@news.th-darmstadt.de (The News System)
- Message-ID: <1992Dec22.171004@rbg.informatik.th-darmstadt.de>
- Date: Tue, 22 Dec 1992 16:10:04 GMT
- References: <HBF.92Dec19163113@gandalf.uio.no>
- Nntp-Posting-Host: rbhp58.rbg.informatik.th-darmstadt.de
- Organization: TH Darmstadt
- Lines: 34
-
- In article <HBF.92Dec19163113@gandalf.uio.no>, hbf@gandalf.uio.no (Hallvard B Furuseth) 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?
-
- Shrug. But at looking on sun's definition of assert() if found following (bug ?):
-
- #define _assert(ex) {if (!(ex)){(void)fprintf(stderr,"Assertion failed: file
- \"%s\", line %d\n", __FILE__, __LINE__);exit(1);}}
- #define assert(ex) _assert(ex)
-
- This wont work in cases like this
-
- #include <stdio.h>
- #include <assert.h>
-
- main()
- { if (42==42) assert(17<23);
- else printf("never");
- }
-
- =>
-
- $cc t.c
- "t.c", line 6: syntax error at or near word "else"
-
- cause it expands to something like this if (...) {...}; else ....
- (Gnu does it right, using a ? : instead of the if, thus having no need
- for the {})
-
- --
- Walter Misar It is impossible to enjoy idling thoroughly
- misar@rbg.informatik.th-darmstadt.de unless one has plenty of work to do.
-