• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Malloc()
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Malloc()
      • From: Jim Correia <email@hidden>
References: 
 >Re: Malloc() (From: Jim Correia <email@hidden>)

  • Prev by Date: Project Builder Bug? No Classes in Classes tab
  • Next by Date: Drawing to NSImage as PDF
  • Previous by thread: Re: Malloc()
  • Next by thread: Re: Malloc()
  • Index(es):
    • Date
    • Thread