Path: utzoo!mnetor!uunet!husc6!bloom-beacon!gatech!hao!oddjob!gargoyle!ihnp4!ihlpg!tainter From: tainter@ihlpg.ATT.COM (Tainter) Newsgroups: comp.lang.c Subject: Re: Arrays and structures Message-ID: <4675@ihlpg.ATT.COM> Date: 21 Jan 88 05:01:44 GMT References: <22151@linus.UUCP> Organization: AT&T Bell Laboratories - Naperville, Illinois Lines: 45 In article <22151@linus.UUCP>, jfjr@mitre-bedford.ARPA (Jerome Freedman) writes: > Suppose I have the following > typedef struct /* I despise structure tags */ > { > /* some irrelevant field declarations */ > char string[80]; > int vector [4]; > } structure_type; > structure_type first_structure,second_structure; > /* The various fields of first_structure get filled */ > /* and somewhere in the code I do this */ > second_structure = first_structure; /* ANSI standard allows this */ > Now, tell me about the string and vector fields of second structure. > Since they are arrays then the fields are actually pointers. I know of only one implementation of C where this is the case. In all the others arrays are inline contiguous elements of the array. That one implementation is for Amdahl IBM clones (big ones, not toys). In such a scheme the compiler is responsible for generating code to copy the pointed at array data rather than the pointers and the pointers should be unique so that subsequent modifications do not modify both. This is the price they pay for using an unusual, nonintuitive implementation for arrays. > Is the situation different if I change the type declaration to > typedef struct /* I despise structure tags */ > { > /* some irrelevant field declarations */ > char *string; > int *vector; > } structure_type; Yes, with this it should copy the pointers, not the pointees :-). > Jerry Freedman, Jr "Thank you, folks, --j.a.tainter