Casting a postdecrement operand

Davidsen davidsen at steinmetz.UUCP
Wed Jun 25 05:39:25 AEST 1986


In article <1295 at ulysses.UUCP> jss at ulysses.UUCP (Jerry Schwarz) writes:
>> 
>> The variable 'cbap' is a pointer. The cast '(struct abc *)' is a
>> pointer cast. I can use '((struct abc *)cbap)' with indirects and
>> subscripts and anywhere that I can use an Lvalue, so I really believe
>> that the expression is legal.
>> 	-bill davidsen
>
>Being a pointer value is not the same as being an lvalue. The places
>that require lvalues are left hand side of assignments, and operands
>of the increment and decrement operations. In none of these locations
>is '((struct abc*)cbap)' legal.

>> subscripts and anywhere that I can use an Lvalue, so I really believe
					     ^^^^^^
A thousand pardons! I was thinking about Lvalues, and wrote Lvalue
where I meant "address value". The point I was making (trying to amke)
was that the result of the cast operation is legen *in* an Lvalue,
where a pointer would be, not that I thought it was an Lvalue as is.
  Example:
	*((float *) ptr) = 4.5; /* ptr is char * type */

The other question was the legality of a cast on increment, and rather
than read books and standards, I actually tried it, based on the theory
that what happened in most places is "current practice". So far I have
found 3 of seven compilers which compile code for
  ((float *) ptr)++; /* ptr type is char * */
so I make no claims one way or the other.

NOTE: I am not claiming that either of these is portable or useful, but
that's not the same thing as valid. Current practice is why enums are
done as integers rather than being truly a distinct data type. They
were added because the preprocessor ran out of symbol space as far as I
know.

Thanks to the people who pointed out the poor explanation in the
earlier posting. All were polite except one jerk who sent six screens
of flames and a ficticious .signature at the end. I hope this didn't
confuse anyone.
-- 
	-bill davidsen

  ihnp4!seismo!rochester!steinmetz!--\
                                       \
                    unirot ------------->---> crdos1!davidsen
                          chinet ------/
         sixhub ---------------------/        (davidsen at ge-crd.ARPA)

"Stupidity, like virtue, is its own reward"



More information about the Comp.lang.c mailing list