sizeof a struc field

Bill Poser poser at csli.Stanford.EDU
Wed Oct 25 09:08:09 AEST 1989


I am curious as to when someone would want to take sizeof(((T *) 0)->member).
If you need to know the size of a structure member, you can always consult
the structure definition, discover that member is, say, of type "int",
and write sizeof(int). If you want to allow for future changes in the
member's type, use the preprocessor and make both the definition and
the argument to sizeof macros, e.g.

#define INTEGRAL int
#define REAL double

struct foo{
	INTEGRAL a;
	REAL b;
};

Then you get the size of the a member as:

sizeof(INTEGRAL)

Perhaps one can argue that this isn't the most perspicuous thing to do,
but it seems easy enough that I am curious as to how outlawing the
null pointer construction can be seen as reducing C functionality in
any significant way.

						Bill



More information about the Comp.lang.c mailing list