foo = *((bar *)stuff)

joe at modcomp.UUCP joe at modcomp.UUCP
Wed May 3 03:52:00 AEST 1989


yair at tybalt.caltech.edu writes:
>Sven (Sciz) Axelsson writes:
>>Isn't this code supposed to assign the integer value contained
>>at memory position 10 to the variable x?
>>
>>	x = *((int *)10);
>>
>(int *) 10 should convert the integer 10 to a pointer, then the *
>should dereference the pointer, which on most (*not* all) machines
>should read location 10 of memory.  Note that this is extremely
>nonportable and very machine (even compiler) dependent.  [...] On 80x86
>machines this can cause problems since 'far' pointers may be different
>from 'near' pointers, ...

One (word-oriented) machine I've worked on had pointers of different
types with different internal representations.  A (char *)10 would reference
the 10'th *byte* of memory and a (int *)10 the 10'th *word* of memory.
Clearly, a very nonportable construct!

joe korty
uunet!modcomp!joe



More information about the Comp.lang.c mailing list