typedefs and structs

Douglas McNaught doug at mcnaught.org
Wed Nov 9 11:59:56 EST 2005


linas <linas at austin.ibm.com> writes:

> On Tue, Nov 08, 2005 at 07:37:20PM -0500, Douglas McNaught was heard to remark:
>> 
>> Yeah, but if you're trying to read that code, you have to go look up
>> the declaration to figure out whether it might affect 'foo' or not.
>> And if you get it wrong, you get silent data corruption.
>
> No, that is not what "pass by reference" means. You are thinking of
> "const", maybe, or "pass by value"; this is neither.  The arg is not 
> declared const, the subroutine can (and usually will) modify the contents 
> of the structure, and so the caller will be holding a modified structure
> when the callee returns (just like it would if a pointer was passed).

Right.  My point is only that it's not clear from looking at the call
site whether a struct passed by reference will be modified by the
callee (some people pass by reference just for "efficiency").  And if
the called function modifies the data without the caller's knowledge,
it leads to obscure bugs.  Whereas if you pass a pointer, it's
immediately clear that the called function can modify the pointed-to
object.

-Doug



More information about the Linuxppc64-dev mailing list