[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Release check
From: |
Jeremy Bettis |
Subject: |
Re: Release check |
Date: |
Thu, 2 Jun 2005 14:51:26 -0500 |
Under what circumstances would it be necessary to include Protocol.h?
Does this affect just the libraries or also user code?
Also, it seems like a pain to need to include Protocol.h to ask an object
if if conformsTo: @protocol(...), but this is the way NeXT did it so I
guess we are stuck with that. If I were redesigning this from scratch I
would make sure all Objective-C language features were pulled in by one
include -- if that.
Protocol.h is only needed to send messages to a Protocol object.
I think that having NSObject.h not include Object.h is a great idea. Also
to make this discussion concrete, I have a sample program that represtents
typical "user" use of Protocols. This causes ZERO warnings in gcc 3.4.2
I put a NSObject inline here to show how it might work if NSObject did not
include Object.h
/*
gcc -g -I$GNUSTEP_ROOT/System/Library/Headers -Wall prottest.m -o
prottest.exe -L$GNUSTEP_ROOT/System/Library/Libraries -lgnustep-base -lobjc
&& ./prottest
*/
#include <objc/objc.h> // Defines id, BOOL and @class Protocol
@interface NSObject
+ (id) new;
+ (id) alloc;
- (id) init;
- (id) retain;
- (void) release;
- (void) dealloc;
- (BOOL) conformsToProtocol:(Protocol*)p;
@end
@protocol AA
- (void) foo;
@end
@interface A : NSObject <AA>
@end
@implementation A
- (void) foo
{
}
@end
int main()
{
A *a = [A new];
if ([a conformsToProtocol:@protocol(AA)]) {
[a foo];
}
[a release];
return 0;
}
And here is a concrete example of unusual use of Protocols that might cause
a warning in existing code if #include <objc/Protocol.h> was not there.
Protocol *aa = @protocol(AA);
[aa name];
Causes this warning:
warning: `Protocol' may not respond to `-name'
warning: (Messages without a matching method signature
warning: will be assumed to return `id' and accept
warning: `...' as arguments.)
I think we can all live with that.
Re: Release check, Sheldon Gill, 2005/06/02
Re: Release check, Fred Kiefer, 2005/06/02