Xref: utzoo comp.lang.c:26299 comp.std.c:2512 Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!hellgate.utah.edu!ug.utah.edu!efinley From: efinley%ug.utah.edu@cs.utah.edu (Elliott Finley) Newsgroups: comp.lang.c,comp.std.c Subject: Re: const and struct pointers Message-ID: <1990Feb25.143429.21359@hellgate.utah.edu> Date: 25 Feb 90 21:34:29 GMT References: <1214@watserv1.waterloo.edu> <90054.232325CMH117@psuvm.psu.edu> Distribution: all Organization: University of Utah CS Dept Lines: 33 (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. Here is an excerpt from K&R2, chapter 6, page 127 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- The main change made by the ANSI standard is to define structure assignment--structures may be copied and assigned to, passed to functions, and returned by functions. This has been supported by most compilers for many years, but the properties are now precisely defined. Automatic structures and arrays may now also be initialized. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Chapter 6.2 page 129 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Let us investigate structures by writing some functions to manipulate points and rectangles. There are at least three possible approaches: pass components separately, pass an entire structure, or pass a pointer to it. Each has its good points and bad points. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- So you can clearly see that the statement made above "But the struct is passed by reference (as are *all* structures in C!)" is not true! Elliot P.S. It is ALOT more efficient to pass a pointer to a structure.