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
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]