sizeof a struc field

Lloyd Kremer kremer at cs.odu.edu
Sat Oct 28 04:37:18 AEST 1989


In article <1503 at crdos1.crd.ge.COM> davidsen at crdos1.UUCP (bill davidsen) writes:
>In article <1003 at cirrusl.UUCP>, dhesi at sunseeker.UUCP (Rahul Dhesi) writes:
>
>|          sizeof ((type *)x)->member
>
>  If x is not a pointer type I'm sure you mean 
>	sizeof ((type *)&x)->member
>			^

I'm fairly sure he meant it the first way--an integral constant expression
to be used as a pointer to some object (in this case a struct) in a totally
non-portable way.

Uses include accessing interrupt vectors or memory-mapped devices such as
the video map or RAM designated for use by the system BIOS.

One problem that comes to mind (other than obvious non-portability) is the
familiar pointer alignment problem.  I think

	((type *)1)->member

would cause a trap on any machine requiring any alignment of "type".

					Lloyd Kremer
					kremer at cs.odu.edu
					Have terminal...will hack!



More information about the Comp.lang.c mailing list