incrementing after a cast

der Mouse mouse at mcgill-vision.UUCP
Tue Dec 9 19:58:32 AEST 1986


In article <2319 at mtgzz.UUCP>, bds at mtgzz.UUCP writes:
> In article <349 at apple.UUCP>, kanner at apple.UUCP (Herbert Kanner) writes:
>> 		L = *((sometype *) chp)++;
>> Our problem arises with the allegation that K&R makes this construct
>> illegal.
> By parenthesising the expression:
> 	L = (*((sometype *) chp))++
> Then [it's legal].
> Happily, it is the one you want.

I certainly hope not.  The intent was clearly to increment chp by
sizeof(sometype), or something very much like that.  Your proposed
parse results in an expression that doesn't touch chp; even *it* won't
be legal unless "sometype" can have ++ applied to it - for it's
something of type "sometype" that it's ++ing.

You also mention (I deleted it) that this parse is generated even
without the parentheses.  Well, I don't know what compiler you're
using.  Here is what my machine (VAX750/MtXinu4.3+NFS) gives:

	% cat x.c
	main()
	{
	 int i;
	 int j;
	 char *cp;
	
	 cp = (char *) &i;
	 j = *((int *)cp)++;
	}
	% cc x.c
	"x.c", line 8: illegal lhs of assignment operator
	%

					der Mouse

USA: {ihnp4,decvax,akgua,utzoo,etc}!utcsri!mcgill-vision!mouse
     think!mosart!mcgill-vision!mouse
Europe: mcvax!decvax!utcsri!mcgill-vision!mouse
ARPAnet: think!mosart!mcgill-vision!mouse at harvard.harvard.edu

[USA NSA food: terrorist, cryptography, DES, drugs, CIA, secret, decode]



More information about the Comp.lang.c mailing list