Casting a postdecrement operand

Gregory Smith greg at utcsri.UUCP
Mon May 26 11:25:18 AEST 1986


In article <114 at romp.UUCP> lwh at romp.UUCP (lwh) writes:
>My version of pcc on the IBM RT PC allows the following expression:
>
>		struct abc { char d[500]; };
>		struct cba { char e[200]; };
>		struct cba *cbap;
>
>		((struct abc *)cbap)++;
>
>
>to increment cbap by 500. It appears that the ANSI standard doesn't say
>anything about the legality of this syntax.  
>
First, a technical point: There is nothing wrong with the `syntax', which
is identical to the syntax of
		(( struct foobar * ) pp )++;
The *semantics*, though, are a different question. You are saying
'Treat cbap as a pointer to a (struct abc); increment that pointer'.
The compiler dutifully adds 500. ( You asked for it, you got it... )
This is perfectly legal, but lint might well want to prod you about it...
Since you are explicitly casting the pointer, though, it should be plain
that you have good reasons to do so.

-- 
"We demand rigidly defined areas of doubt and uncertainty!" - Vroomfondel
----------------------------------------------------------------------
Greg Smith     University of Toronto      UUCP: ..utzoo!utcsri!greg



More information about the Comp.lang.c mailing list