• 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: 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.

  • Follow-Ups:
    • Re: Malloc()
      • From: Ondra Cada <email@hidden>
    • Re: Malloc()
      • From: Kaelin Colclasure <email@hidden>
References: 
 >Re: Malloc() (From: Chris Hanson <email@hidden>)

  • Prev by Date: Moving the Dev Tools Docs?
  • Next by Date: Re: Toplevel Objects in NIB files
  • Previous by thread: Re: Malloc()
  • Next by thread: Re: Malloc()
  • Index(es):
    • Date
    • Thread