Xref: utzoo comp.std.c:2504 comp.lang.c:26279 Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!uakari!uflorida!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.std.c,comp.lang.c Subject: Re: const and struct pointers Message-ID: <12227@smoke.BRL.MIL> Date: 24 Feb 90 18:29:56 GMT References: <1214@watserv1.waterloo.edu> <90054.232325CMH117@psuvm.psu.edu> Reply-To: gwyn@brl.arpa (Doug Gwyn) Followup-To: comp.std.c Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 22 In article <90054.232325CMH117@psuvm.psu.edu> CMH117@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.