RE: where have all the IVARS gone? (long time passing...)
RE: where have all the IVARS gone? (long time passing...)
- Subject: RE: where have all the IVARS gone? (long time passing...)
- From: Vinay Prabhu <email@hidden>
- Date: Mon, 10 Jul 2006 12:41:52 +0530
- Importance: Normal
Thanks for resolving the confusion which I had,
I was expecting error or warning for the multiple declaration, might be that
is a defect...
Regards
Vinay
-----Original Message-----
From: Bill Bumgarner [mailto:email@hidden]
Sent: Monday, July 10, 2006 12:34 PM
To: Vinay Prabhu
Cc: 'Rob Ross'; email@hidden
Subject: Re: where have all the IVARS gone? (long time passing...)
On Jul 9, 2006, at 11:49 PM, Vinay Prabhu wrote:
I am confused,
If I declare any variables under the directive
@interface myClass
@end
Is the scope of iVras are not limited to myClass?
Only if they are surrounded in {}s. I.e.
@interface MyClass
{
int iVar;
}
@end
Otherwise, you are declaring global variables.
And, unfortunately, you can't add instance variables to a class via a
category; this won't work:
@interface MyClass (Private)
{
int anotherVar;
}
@end
Yes, I am using only one instance of object from myClass.
May be because of this, I haven't noticed the problem... :(
....
In the implementation file if I declare few variables like this,
@interface myClass1 (Private)
int iVar;
@end
@interface myClass2 (Private)
int iVar;
@end
What will be the scope of iVar?
Global.
I have tried this, it compiles without any errors!!!
If iVar is global, compiler should have given error for multiple
declaration...
Yeah -- you would think you would get a warning... but you don't!
Given foo.c with contents:
int ivar1;
int ivar1;
int main() {
return 1;
}
% cc -Wall foo.c
%
No warnings. That seems like a bug to me.
Consider:
#import <Foundation/Foundation.h>
@interface A:NSObject
+(void)go;
@end
@interface B:NSObject
+(void)go;
@end
@implementation A
@end
@implementation B
@end
@implementation A (private)
int iVar1;
+(void)go
{
NSLog(@"A: 0x%x", &iVar1);
}
@end
@implementation B (private)
int iVar1;
+(void)go
{
NSLog(@"B: 0x%x", &iVar1);
}
@end
int main() {
[A go];
[B go];
NSLog(@"main(): 0x%x", &iVar1);
return 0;
}
The output:
% gcc foo.m -framework Foundation
foo.m:10: warning: incomplete implementation of class `A'
foo.m:10: warning: method definition for `+go' not found
foo.m:12: warning: incomplete implementation of class `B'
foo.m:12: warning: method definition for `+go' not found
% ./a.out
2006-07-10 00:03:51.287 a.out[520] A: 0x30b4
2006-07-10 00:03:51.288 a.out[520] B: 0x30b4
2006-07-10 00:03:51.288 a.out[520] main(): 0x30b4
The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s)and may contain confidential or privileged information. If you are not the intended recipient, please notify the sender or email@hidden
_______________________________________________
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