A quick question...

Stanley Friesen sarima at tdatirv.UUCP
Wed Mar 13 03:37:47 AEST 1991


In article <1991Mar12.030759.26698 at nntp-server.caltech.edu> eychaner at suncub.bbso.caltech.edu writes:
>Just a quick question...I personally still don't quite understand what is
>and is not legal on the left side of an assignment.
>Is this legal...
>	unsigned char *pointer1;
>	short short_value;
>	...
>	*((short *) pointer1) = short_value;
>	...
>And does it do what I think it does, that is, assign short_value to the
>storage pointed to by pointer1?  I hope you understand what I mean...

Assuming that you have initialized pointer1 to point to a suitably alligned
block of memory at least large enough to hold one short, then yes.

If the pointer1 is uninitialized, or points to an improperly alligned block,
or points to a block that is too small then the result is undefined.

To put it another way:
Dereferencing a pointer always yields an lvalue if the pointer is valid.
If the pointer is invalid, the dereference yields undefined results.
-- 
---------------
uunet!tdatirv!sarima				(Stanley Friesen)



More information about the Comp.lang.c mailing list