const and struct pointers
Doug Gwyn
gwyn at smoke.BRL.MIL
Sun Feb 25 05:29:56 AEST 1990
In article <90054.232325CMH117 at psuvm.psu.edu> CMH117 at psuvm.psu.edu (Charles Hannum) writes:
>The double is passed by value; so dereferencing it works fine. But the
>struct is passed by reference (as are *all* structures in C!). In reality,
>you need to pass a "struct qwert *" to the function. Normally, the compiler
>takes the reference automatically, but you are trying to do this in reverse.
>Thus, it does not work; you simply can't pass a structure by value.
You shouldn't answer questions when you don't know what you're talking
about. Structure arguments to functions are passed by value, not by
reference. The implementation may play funny games that amount to
building a private copy of the structure and passing a reference to
the private copy, but from the point of view of the programmer the
structure is passed by value and has exactly the properties one would
expect for the by-value mechanism.
The compiler was correct to complain about an argument that had as its
type "pointer to qualified type" being passed to a function expecting
a pointer to an unqualified type. That violates 3.3.16.1 (as referred
to in 3.3.2.2); and that is a logical constraint for the standard to
have imposed, because the function may try to store into the pointed-to
location but since the pointed-to storage is actually defined as having
the const attribute that would be a mistake.
More information about the Comp.lang.c
mailing list