prev up next   top/contents search

comp.lang.c FAQ list · Question 2.7

Q: I heard that structures could be assigned to variables and passed to and from functions, but K&R1 says not.

A: What K&R1 said (though this was quite some time ago by now) was that the restrictions on structure operations would be lifted in a forthcoming version of the compiler, and in fact the operations of assigning structures, passing structures as function arguments, and returning structures from functions were fully functional in Ritchie's compiler even as K&R1 was being published. A few ancient compilers may have lacked these operations, but all modern compilers support them, and they are part of the ANSI C standard, so there should be no reluctance to use them. [footnote]

(Note that when a structure is assigned, passed, or returned, the copying is done monolithically. This means that the copies of any pointer fields will point to the same place as the original. In other words, the data pointed to is not copied.)

See the code fragments in question 14.11 for an example of structure operations in action.

References: K&R1 Sec. 6.2 p. 121
K&R2 Sec. 6.2 p. 129
ISO Sec., Sec., Sec. 6.3.16
H&S Sec. 5.6.2 p. 133

prev up next   contents search
about this FAQ list   about eskimo   search   feedback   copyright

Hosted by Eskimo North