structure element offsets

Michael Meissner meissner at dg_rtp.UUCP
Sun Dec 14 04:22:09 AEST 1986


In article <419 at viper.UUCP> dave at viper.UUCP (David Messer) writes:
>
> Because your solution doesn't work all the time either.  There are
> some machines in which pointers to different types are unrelated
> in format.  In other words a cast such as (type1 *)(type2 *)x
> will not always give a meaningful answer.  According to K&R all
> that is required is that (type *)(long *)x == x.

I hate to be picky, but what K&R requires is that:

	(type *)(char *)x == x

work (ie, it will only work if the pointer type you are converting to is
of less strict alignment (or the same) and back again.  ANSI X3J11 goes
further, and mandates that function pointers are not allowed to be converted
to object pointers.  For word based machines (like the Data General MV-series
computers), this conversion may cause conversion, to/from the pointer type.

	Michael Meissner
	Data General
	...!mcnc!rti-sel!dg_rtp!meissner



More information about the Comp.lang.c mailing list