🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.bugs.4bsd
Article #86

Re: Ultrix CC bug?

#86
From: Maarten Litmaath
Date: Fri, 15 Sep 1989 19:21
56 lines
2090 bytes
bl@infovax.UUCP (Bj|rn Larsson) writes:
\...	*((long *) p)++		has the value of the *long* pointed
\				to by p, and the *long* pointer is
\				set to point to the next long (i.e.
\				if sizeof (long)== 2*sizeof(short)
\				then p will be incremented by two,
\				counted in short's).
\
\  Any objections? I could add that both Turbo C, MicroSoft C, and the
\MicroTek C 68000 cross-compiler compile this as I believe 'correctly'.

It seems all those compilers are wrong...!
Now where's that article I posted not too long ago to comp.lang.c?
Aha!  Here it is.
Allright.  A compiler that allows the abovementioned construct is wrong for
two reasons:

1)	It allows the `++' operator to be applied to an Rvalue expression;
	only Lvalue expressions may be operand of an increment operator, e.g.

		x++
		a[i]++

	This isn't so strange:

		x++
	
	is equivalent to

		x = x + 1

	which doesn't make sense for arbitrary (Rvalue) expressions.
2)	It increments the wrong variable; a cast is equivalent to an
	assignment to an invisible temporary variable (with the usual
	restrictions and conversions):

		foo	x;

		... (bar) x ...

	becomes

		foo	x;
		bar	cast_tmp;	/* `invisible' temp variable */

		... (cast_tmp = x) ...
	
	If we write the latter expression as

		(cast_tmp = x, cast_tmp)

	it's clearly `cast_tmp' which should be incremented (if a `++'
	operator is appended), were this possible at all; definitely NOT `x'.
-- 
   creat(2) shouldn't have been create(2): |Maarten Litmaath @ VU Amsterdam:
      it shouldn't have existed at all.    |maart@cs.vu.nl, mcvax!botter!maart
Technical Details
Message-ID: <3270@solo5.cs.vu.nl>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!mcsun!hp4nl!star.cs.vu.nl!maart
References: <199@infovax.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!mcsun!hp4nl!star.cs.vu.nl!maart
From: maart@cs.vu.nl (Maarten Litmaath)
Newsgroups: comp.bugs.4bsd,eunet.bugs.4bsd
Subject: Re: Ultrix CC bug?
Summary: NO bug in cc!
Keywords: Ultrix, BSD4.x, CC, Bug?
Message-ID: <3270@solo5.cs.vu.nl>
Date: 15 Sep 89 19:21:34 GMT
References: <199@infovax.UUCP>
Organization: V.U. Informatica, Amsterdam, the Netherlands
Lines: 56