Re: Which exception handling system should I use?
Re: Which exception handling system should I use?
- Subject: Re: Which exception handling system should I use?
- From: "Clark Cox" <email@hidden>
- Date: Thu, 27 Apr 2006 07:40:39 -0400
On 4/25/06, Brian Stern <email@hidden> wrote:
> >If you are using Objective-C++ then there is another minus to @try:
> >- marks variables in the subroutine with the @try block as volatile
>
> >block. Why variables are marked as volatile in the first place, I
> >have no idea. Maybe someone can explain that.
>
> Some time ago, in the GCC 2.95 days, I worked on a C++ project that had
> been developed in CodeWarrior and was being ported to GCC. We discovered a
> bug in GCC in code like the following:
>
> SomeClass s = 0;
> try {
> SomeFuncThatMightThrow();
> s = GetAnS();
> } catch (...) {
> delete s;
> }
>
> The GCC optimizer optimized away the initial assignment to zero, presumably
> because it thought that s was being assigned to twice in a way that only
> the second assignment mattered. So if an exception was thrown before s was
> assigned the delete call would crash because s was filled with garbage.
> Curiously our work-around was to explicitly mark variables like s as
> volatile.
>
> This bug was eventually fixed in later versions of GCC and I can only
> assume from your comments that it was fixed by implicitly marking s as
> volatile, to inhibit the incorrect optimization. This fix seems like a
> hack.
No, the implicit volatile *only* happens with Objective-C @try/@catch
blocks, not with C++ try/catch blocks.
--
Clark S. Cox III
email@hidden
My CV/Resume:
http://homepage.mac.com/clarkcox3/files/Resume.pdf
http://homepage.mac.com/clarkcox3/files/Resume.html
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden