structure element offsets

Karl Heuer karl at haddock.UUCP
Wed Dec 10 14:46:59 AEST 1986


In article <427 at viper.UUCP> dave at viper.UUCP (David Messer) writes:
It is
>interesting in that the only thing gaurenteed about casts on pointers is the
>conversion to a long and back and conversion to a pointer to a smaller type
>and back, which also results in the same original pointer value.  One
>interesting thing is, by these rules, the use of malloc(), for anything other
>than char arrays, is non-portable.

No, it isn't.  The *implementation* of malloc() is nonportable, but since it
is guaranteed to return a maximally-aligned "char *" (the result of casting
a widetype pointer, which, as you mentioned, may be safely cast back), its
use is portable.  (Well, I guess if you want to nit-pick, the rules you quoted
don't specifically allow (int *)(char *)(double *)double_aligned_intptr; is
that what you mean?)

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list