Re: Malloc()
Re: Malloc()
- Subject: Re: Malloc()
- From: Kaelin Colclasure <email@hidden>
- Date: Wed, 03 Apr 2002 10:25:21 -0800
On 4/2/02 5:22 PM, "Jim Correia" <email@hidden> wrote:
>
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.
Following your logic above, better to use sizeof (*pointer).
>
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.
By using indirection you eliminate the inconsistency, and further reduce the
chance of the class of error you allude to above.
-- Kaelin
_______________________________________________
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: Jim Correia <email@hidden>) |