Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: assert Message-ID: <5677@brl-smoke.ARPA> Date: Sat, 14-Mar-87 15:39:22 EST Article-I.D.: brl-smok.5677 Posted: Sat Mar 14 15:39:22 1987 Date-Received: Tue, 17-Mar-87 01:46:20 EST References: <4907@brl-adm.ARPA> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 28 In article <4907@brl-adm.ARPA> Dizio@udel.edu writes: >#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) > >My question is this. Is this a proper implementation of this >functionality. I'm not sure why it wants to pass the EX to >_assert except perhaps to print the expression out, but in reality >the line number and file name is all I ever need to know. The problem is that there is no way in K&R C to construct a string literal with a macro argument embedded in it. When Reiser implemented his preprocessor (used by every version of UNIX that I have seen so far), he supported this so that macros such as assert() would work (except for cases such as the one you stumbled across). The CTRL() macro one often encounters uses a similar trick to construct a character constant. X3J11 recognized the need for some such facility, but could not bring themselves to bless this Reiserism, which conflicts with much existing practice on non-UNIX systems. They therefore introduced a "stringize" operator (but not a "charize" one, alas). I don't recall if the Draft Standard points out the need to escape " characters in the macro argument when stringizing, but I think it does (I left my copy at home).