Re: Malloc()
Re: Malloc()
- Subject: Re: Malloc()
- From: Dan Crevier <email@hidden>
- Date: Tue, 02 Apr 2002 20:39:20 -0800
On 4/2/2002 4:22 PM, "Chris Hanson" <email@hidden> wrote:
>
At 5:21 PM +1000 4/2/02, Pete Yandell wrote:
>
> As a counterexample, sizeof will do the right thing for statically
>
> allocated data, so if you declare buffer as:
>
>
>
> char buffer[129];
>
>
>
> then sizeof(buffer) will give you the expected 129 because the
>
> compiler will know the size at compile time when sizeof is evaluated.
>
>
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'd actually argue that that's the perfect reason to use sizeof on variables
rather than types. If you do something like memset to clear out a variable
using the wrong type/size, you are in trouble.
Dan
_______________________________________________
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>) |