Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!ll-xn!cullvax!drw From: drw@cullvax.UUCP (Dale Worley) Newsgroups: comp.lang.c Subject: assert Message-ID: <936@cullvax.UUCP> Date: Wed, 18-Mar-87 17:41:18 EST Article-I.D.: cullvax.936 Posted: Wed Mar 18 17:41:18 1987 Date-Received: Fri, 20-Mar-87 02:18:02 EST Organization: Cullinet Software, Inc., Westwood, MA Lines: 37 Dizio@udel.edu writes: > I found this macro for assert in under ULTRIX 1.2 > under the SYSTEM_FIVE #ifdef > > #define assert(EX) if (EX) ; else _assert("EX", __FILE__, __LINE__) > ^culprit > > It fails when given given an expression containing '"'. > eg. assert ((fp = fopen("filename","r")) != NULL) > > I realize this is a minor point as I could simply write my own macro, > but I just wondered if the proposed standard has specified whether > any valid expression should be able to be used inside the assert, > Or only expressions which don't contain '"'. The standard requires that assert() work for any expression. But, if you want to write your own assert(), you can do things like #define assert(EX) ( (EX) ? _assert(#EX, __FILE__, __LINE__) ANSI C won't let you substitute parameters inside quoted strings, but it will let you convert a parameter into a string literal via #. # is also required to handle things containing "s correctly. E.g., #define stringify(EX) #EX stringify(printf("Foo\n")) yields "printf(\"Foo\\n\")" Dale -- Dale Worley Cullinet Software UUCP: ...!seismo!harvard!mit-eddie!cullvax!drw ARPA: cullvax!drw@eddie.mit.edu Un*x (a generic name for a class of OS's) != Unix (AT&T's brand of such)