Structures

Henry Spencer henry at utzoo.uucp
Sat Mar 3 04:14:07 AEST 1990


In article <14302 at reed.UUCP> minar at reed.bitnet (Nelson Minar) writes:
>My copy of K&R 1 (I'll be getting 2 soon..) says
>"There are only two things that can be done with a structure or a union...

K&R1 was obsolete a decade ago, in this and some other minor respects.

>1] What does ansi say about this?

Structures can be assigned, passed, and returned, plus (with some limits)
initialized.

>2] It seems that passing a structure-by-value is illegal under this rule.
>Why this limitation in the original C?

Basically because C came out of the BCPL heritage, in which there was
really only one data type (the word) and all values were one word wide.
C departed from this pretty early for floating point, but bigger departures
were slow in coming.  Passing pointers to structs is usually more efficient
and met most early needs just as well.

>3] My C compiler (Turbo C 2.0) doesn't mind passing a structure-by-value,
>and it allows you to set two structures equal to each other, automatically
>copying the elements. Is this standard behavior for most C compilers? Why
>does Turbo C have an <optional> warning "Warning: structure passed by value"
>if it is legal TC 2.0 code? Because it is potentially non-portable?

It's standard behavior for modern compilers; the warning is probably
because it's not K&R1 conformant.
-- 
MSDOS, abbrev:  Maybe SomeDay |     Henry Spencer at U of Toronto Zoology
an Operating System.          | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list