Re: OK to talk about 3.2.2+ and new compiler?
Re: OK to talk about 3.2.2+ and new compiler?
- Subject: Re: OK to talk about 3.2.2+ and new compiler?
- From: "Paul Sanders" <email@hidden>
- Date: Tue, 22 Jun 2010 10:25:36 +0100
> Is there an option that we can enable to force the compiler to emit
warnings any time we make
> assignments to untyped classes? I really hate the fact that
mistakes like these are so simple to make.
I don't believe there is, no. You could however
define a macro along these lines:
#define ALLOC_OBJECT(cls, ini,
...) (cls *) [((cls *) [cls alloc]) ini, ## __VA_ARGS__]
And then you can do this:
MySuperDuperClass *obj = ALLOC_OBJECT
(MySuperDuperClass, init);
[obj autorelease];
Or this:
MySuperDuperClass *obj = ALLOC_OBJECT
(MySuperDuperClass, initWithX: x Y: y);
Or even this:
MySuperDuperClass *obj = ALLOC_OBJECT
(MySuperDuperClass, initWithObjects: obj1, obj2, nil);
The nice thing about this approach is
that you can adapt your source code piecemeal.
The second, interior cast is in there
to disambiguate initxxx methods if two different classes happen to define
the same method signature. There was a thread about this on cocoa-dev a
couple of months ago. It doesn't happen often but it can be confusing - or
even downright dangerous - when it does.
GCC's extended support for variadic macros is rather nice,
is it not?
Regards,
Paul Sanders.
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden