Re: Malloc()
Re: Malloc()
- Subject: Re: Malloc()
- From: Jim Correia <email@hidden>
- Date: Tue, 2 Apr 2002 20:22:53 -0500
On Tuesday, April 2, 2002, at 07:22 PM, Chris Hanson wrote:
I *never* use the sizeof operator on a variable, because the type the
compiler thinks the variable is isn't always the type the programmer
thinks the variable is. I only ever use the sizeof operator on a type,
because that will do the right thing in all cases.
I actually follow the sizeof(variable) when the variable is not a pointer
type almost always because I've made the mistake before of changing the
type of a local variable, and not updating the sizeof(Type) next to it in
a memset, etc.
Of course, for pointer types, when you want the size of the thing pointed
to, I always use sizeof(Type) because sizeof(pointer) will obviously give
the wrong answer.
I know it is an inconsistent ruleset when compared to each other, but when
applied consistently throughout my code it has caught/prevented bugs from
shipping.
Or are you thinking of a different case where the compiler does the wrong
thing independent of human error?
Jim
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: | |
| >Re: Malloc() (From: Chris Hanson <email@hidden>) |