Assert expressions with strings

Lyndon VanWagner lvw at rama.UUCP
Fri Mar 8 00:57:33 AEST 1991


We have just ran into a problem using the assert() macro, as defined in
/usr/include/assert.h under Ultrix 4.0+, on a DECstation 3100/5000.
We had wanted to perform an assertion of a string (char *) against the
empty string:
	assert(!strcmp(cp,""))

The problem occurs because Ultrix's assert attempts to print the
assertion expression by the following:
	#define assert(EX)	if (EX) ; else  __assert("EX",__FILE__,__LINE__)

We get a syntax error upon the expanded "EX" when EX contains double quotes.
How is everyone else handling this problem?  We had never run into this
before because we hand never tried using an expression with quotes.

Can you help us by giving the answer to this general problem?
Oh, by the way, this is also the way AT&T defined assert in System V rel 2.
This is no problem under SunOS 4.1+, as they don't try expanding the
expression!

Thankyou.
-- 
-----------------------------------------------------------------------------
Lyndon C. VanWagner		Internet:lvw at rama.sc.harris.com
Software Engineer		-or-	rama!lvw at uu.psi.com
Framework Development Group	UUCP:	...!{uupsi,tropix}!rama!lvw
Harris Corporation		PHONE:	(716) 924-9303 ext. 226
Scientific Calculations Division, Fishers, NY 14453
-----------------------------------------------------------------------------
Cornfield's Law (paraphrased):
	Before anything can change, everyone must agree.
	By the time that happens its a different problem.
-----------------------------------------------------------------------------



More information about the Comp.unix.programmer mailing list