Re: typedefs and structs

From: Douglas McNaught
Date: Tue Nov 08 2005 - 19:39:14 EST


linas <linas@xxxxxxxxxxxxxx> writes:

> On Tue, Nov 08, 2005 at 06:57:11PM -0500, Kyle Moffett was heard to remark:

>> That technique tends to cause more problems than it solves. If I
>> write the following code:
>>
>> struct foo the_leftmost_foo = get_leftmost_foo();
>> do_some_stuff(the_leftmost_foo);
>>
>> How do I know what it is going to do?
>
> It depends on how do_some_stuff() was declared. If its declared as
>
> do_some_stuff (struct foo &x)
>
> then it will be a pass by reference.

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.

I'd rather pass a pointer explicitly and crash with a segfault if
someone passes NULL--at least then it's pellucidly clear what went
wrong.

-Doug
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/