typedefs and structs

Kyle Moffett mrmacman_g4 at mac.com
Wed Nov 9 12:51:25 EST 2005


On Nov 8, 2005, at 19:48:08, linas wrote:
> 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).

Pass by value in C:
do_some_stuff(arg1, arg2);

Pass by reference in C:
do_some_stuff(&arg1, &arg2);

This is very obvious what it does.  The compiler does type-checks to  
make sure you don't get it wrong.  There are tools to check stack  
usage of functions too.  This is inherently obvious what the code  
does without looking at a completely different file where the  
function is defined.


Pass by value in C++:
do_some_stuff(arg1, arg2);

Pass by reference in C++:
do_some_stuff(arg1, arg2);

This is C++ being clever and hiding stuff from the programmer, which  
is Not Good(TM) for a kernel.  C++ may be an excellent language for  
userspace programmers (I say "may" here because some disagree,  
including myself), however, many of the features are extremely  
problematic for a kernel.


Cheers,
Kyle Moffett

--
Debugging is twice as hard as writing the code in the first place.   
Therefore, if you write the code as cleverly as possible, you are, by  
definition, not smart enough to debug it.
   -- Brian Kernighan





More information about the Linuxppc64-dev mailing list