another stupid array/pointer question

Daeshik Kim dkim at wam.umd.edu
Sat Mar 3 15:32:44 AEST 1990


In article <1990Mar2.135645.17274 at granite.cr.bull.com> freedman at granite.cr.bull.com (Jerome Freedman) writes:
>
>Suppose I have a structure
>
>    struct a {
>       char * a_string;
>    }
>
>and a structure
>
>    struct b {
>	char another_string[80];
>    }
>
> sizeof(struct a) should equal sizeof(char *)
>
> but what about sizeof(struct b)?
> Is the 80 character array included in the size of struct b or
> is b.another_string a pointer into somewhere  where there is
> allocated space - is this implementation defined?
>
	As far as I know, 'struct a' only has a space for 'ptr';
	but 'struct b' holds 80 bytes statically allocated.

	In most c-compilers, I would say that
		if you have:
			struct b str; /* now, allocated. */
		if you refer str, the address of 'str' should be
		same as the address of 'str.another_string[0]',
		which means that str and str.another_string points
		same location.

	I haven't seen c-compilers with other strategy yet.
--
	Daeshik Kim	H: (301) 445-0475/2147 O: (703) 689-5878
	SCHOOL:	dkim at wam.umd.edu, dskim at eng.umd.edu, mz518 at umd5.umd.edu
	WORK:	dkim at daffy.uu.net (uunet!daffy!dkim)



More information about the Comp.lang.c mailing list