Point me in the right direction

Wade Guthrie evil at arcturus.UUCP
Wed Feb 22 04:26:39 AEST 1989


In article <1043 at auspex.UUCP>, guy at auspex.UUCP (Guy Harris) writes:
[someone started with:]

> double fund_consts[] = {
> 	3.14159265,
> 	2.7182818,
> 	6.02E23,
> };

[and someone else added:]

> Of course, adding:
> 	#define N_FCONSTS (sizeof(fund_consts)/sizeof(double)) 

[and Guy said:] 

> So far, so good - this is an old C trick, which is quite useful, but may
> not be known as well as it should be - but...

[and I say:]

This is all well and good, but what about arrays of structures?  Am I
S.O.L. because of inter-array-element padding if I:

	struct already_defined snarf[] = {...};

and then try to get the size by doing:

	#define N_WHATEVER (sizeof(snarf)/sizeof(struct already_defined))

or can I (portably)

	int size;
	. . .
	size = sizeof(snarf)/(&snarf[1]-&snarf[0]);

(assuming, of course, that snarf has at least 2 elements. . .)


Wade Guthrie
evil at arcturus.UUCP
Rockwell International
Anaheim, CA

(Rockwell doesn't necessarily believe / stand by what I'm saying; how could
they when *I* don't even know what I'm talking about???)



More information about the Comp.lang.c mailing list