side effects inside sizeof

ado at elsie.UUCP ado at elsie.UUCP
Sat Jun 16 12:53:13 AEST 1984


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.



More information about the Comp.lang.c mailing list