typedefs and structs
Douglas McNaught
doug at mcnaught.org
Wed Nov 9 11:37:20 EST 2005
linas <linas at austin.ibm.com> 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
More information about the Linuxppc64-dev
mailing list