Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site elsie.UUCP
Path: utzoo!watmath!clyde!burl!mgnetp!ihnp4!zehntel!hplabs!hao!seismo!rlgvax!cvl!elsie!ado
From: ado@elsie.UUCP
Newsgroups: net.lang.c
Subject: Re: side effects inside sizeof
Message-ID: <965@elsie.UUCP>
Date: Fri, 15-Jun-84 22:53:13 EDT
Article-I.D.: elsie.965
Posted: Fri Jun 15 22:53:13 1984
Date-Received: Fri, 22-Jun-84 05:19:51 EDT
References: <4671@root44.UUCP>
Organization: NIH-LEC, Bethesda, MD
Lines: 41

Here are additions to "/usr/src/cmd/mip/trees.c" (as distributed with 4.1bsd)
to detect side effects inside sizeof and issue a warning.
Since the usual licensing restrictions apply, I'll be vague.

1.  After the declarations in a function named "doszof", add these lines:

	#ifndef OLDVERSION
		if (haseffects(p))
			werror( "operations in object of sizeof are skipped" );
	#endif

2.  Right after the function names "doszof", add these lines:

	#ifndef OLDVERSION
	static int	haseffects(p)
	register NODE *	p;
	{
		register	o, ty;

		o = p->in.op;
		ty = optype(o);
		if (ty == LTYPE)
			return 0;
		if (asgop(o) || callop(o))
			return 1;
		if (haseffects(p->in.left))
			return 1;
		if (ty == UTYPE)
			return 0;
		return haseffects(p->in.right);
	}
	#endif

If you're truly into portability, you can arrange for something more severe than
a warning.
--
	...decvax!allegra!umcp-cs!elsie!ado	(301) 496-5688

EGADS!  All these months of giving an address that includes "decvax" and
I've failed to always note that the VAX in decvax is a Digital Equipment
Corporation trademark.  Please, DEC, hold off on the lawsuit--I plan to reform.