• 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: NSAutoreleasePool and static data member constructors
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSAutoreleasePool and static data member constructors


  • Subject: Re: NSAutoreleasePool and static data member constructors
  • From: "Clark Cox" <email@hidden>
  • Date: Wed, 10 Oct 2007 17:27:44 -0700

On 10/10/07, Uli Kusterer <email@hidden> wrote:
> Am 11.10.2007 um 00:19 schrieb Clark Cox:
> > On 10/10/07, Uli Kusterer <email@hidden> wrote:
> >> So, I don't think you can
> >> use C++ smart pointers and the likes as instance variables. You /have
> >> to/ use pointers and new and delete them properly.
> >
> > Smart pointers take care of this for you.
>
>   Only if their constructors are called. But as we found out, they
> are on 10.4, but if you deploy on 10.3 you'll want to use regular
> pointers and new and delete your C++ objects.
>
> > The rest of your e-mail is spot on:
> > Global autorelease pool or pool created before main() - bad idea
> > Throwing exceptions across language boundaries - bad idea
>
>   You forgot: Implicitly or explicitly relying on initialization
> order of globals or class-static variables - bad idea
>
>   This is really a matter too few C++ programmers are aware of: If
> you have two object-type globals, and one uses the other from its
> constructor, this is *a programming error*.

While I am currently away from my mac (and therefore my copy of the
standard) I do believe that the order of construction is well-defined
if the two objects are defined in the *same translation unit*. Though
I can't say that I've ever relied on that (nor do I plan to) :)

But in the general case, I believe you are correct.

> You cannot know whether
> your target object has already been constructed at the time the
> constructor uses it.
>
> Cheers,
> -- M. Uli Kusterer
> http://www.zathras.de
>
>
>
>


--
Clark S. Cox III
email@hidden
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSAutoreleasePool and static data member constructors
      • From: John Stiles <email@hidden>
References: 
 >NSAutoreleasePool and static data member constructors (From: Erik Buck <email@hidden>)
 >Re: NSAutoreleasePool and static data member constructors (From: "Clark Cox" <email@hidden>)
 >Re: NSAutoreleasePool and static data member constructors (From: Uli Kusterer <email@hidden>)
 >Re: NSAutoreleasePool and static data member constructors (From: "Clark Cox" <email@hidden>)
 >Re: NSAutoreleasePool and static data member constructors (From: Uli Kusterer <email@hidden>)

  • Prev by Date: Re: How an I get an NSAttributedString into an NSView?
  • Next by Date: Re: NSOpenPanel & NSFileTypeForHFSTypeCode
  • Previous by thread: Re: NSAutoreleasePool and static data member constructors
  • Next by thread: Re: NSAutoreleasePool and static data member constructors
  • Index(es):
    • Date
    • Thread