typedefs and structs

Steven Rostedt rostedt at goodmis.org
Wed Nov 9 10:33:35 EST 2005


On Tue, 2005-11-08 at 17:23 -0600, linas wrote:
> On Mon, Nov 07, 2005 at 08:11:13PM -0500, Steven Rostedt was heard to remark:
> > On Mon, 2005-11-07 at 14:41 -0600, linas wrote:
> > 
> > don't use typedef to get rid of "struct".
> > 
> > This was for the simple reason, too many developers were passing
> > structures by value instead of by reference, just because they were
> > using a type that they didn't realize was a structure. 
> 
> That's a rather bizarre mistake to make, since, in order to 
> access a values in such a beast, you have to use a dot . instead 
> of an arrow -> and so it hits ou in the face that you passed a value
> instead of a reference.

It happens when you access the variable via macros and other routines
that you notice that takes and address of the variable, so you just pass
in the address of the current local variable.

> 
> ----
> Off-topic: There's actually a neat little trick in C++ that can 
> help avoid accidentally passing null pointers.  One can declare 
> function declarations as:
> 
>   int func (sturct blah &v) {
>     v.a ++; 
>     return v.b;
>   }
> 
> The ampersand says "pass argument by reference (so as to get arg passing
> efficiency) but force coder to write code as if they were passing by value"
> As a result, it gets difficult to pass null pointers (for reasons
> similar to the difficulty of passing null pointers in Java (and yes,
> I loathe Java, sorry to subject you to that))  Anyway, that's a C++ trick 
> only; I wish it was in C so I could experiment more and find out if I 
> like it or hate it.
> 

Actually, the true pass by reference (not by pointer) is one of the
things that C++ has, that I wish C had.

-- Steve





More information about the Linuxppc64-dev mailing list