This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug objc/49301] Forward declaration of classes broken
- From: "nicola at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 6 Jun 2011 15:51:44 +0000
- Subject: [Bug objc/49301] Forward declaration of classes broken
- Auto-submitted: auto-generated
- References: <bug-49301-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49301
Nicola Pero <nicola at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |nicola at gcc dot gnu.org
--- Comment #3 from Nicola Pero <nicola at gcc dot gnu.org> 2011-06-06 15:51:27 UTC ---
> But could we turn it off with some flag?
Not at the moment. We could add a flag to turn it off if there are enough
important examples.
> And also, in my example, the interface is just BELOW! I think GCC should first
> look furtherâ just a thought.
:-)
> So in programming it must be like this:
>
> The header file has a @class, so the class can be used for variables and
> method arguments.
Yes, header files can use @class to refer to classes defined in other headers
and prevent recursive class definitions. Eg, the header B.h could be:
@class A;
@interface B
- (A *)giveMeA;
@end
and the header A.h could be:
@class B;
@interface A
- (B *)giveMeB;
@end
the two headers are now independent and you can include them independently
with no recursion.
> The method file should have the actual import of the interface, so the
> messages are known, and no recursive import occurs?
Yes, the implementation generally should include full @interfaces for all
the classes that are involved in messaging ... so that the compiler can do
the checks. In the example above, in A.m you would do
#import "A.h"
#import "B.h"
@implementation A
- (B *) giveMeB
{
...
}
@end
and similarly in the implementation of B. No recursive @interface definitions
would occur, and the actual Objective-C code ("..." in the example) has the
full
@interfaces for all the classes and can do full type-checking. :-)
You could also a general header that #imports both A.h and B.h, and #import
that one instead.
Thanks