Re: Is there a bug in #include operation?
Re: Is there a bug in #include operation?
- Subject: Re: Is there a bug in #include operation?
- From: Denis Stanton <email@hidden>
- Date: Tue, 2 Mar 2004 10:22:10 +1300
Hi Chris
Thank you for the almost instant response
I hope you don't mind me copying this back to the list. I would be
interested in any other comments on what I have found.
On Tuesday, March 2, 2004, at 10:02 AM, Chris Anderson wrote:
When I have run into this problem it is inevitably because the class
headers are "cross-fertilized" - meaning, if a Status object has a
"One" reference in it somewhere, and vice versa, the compiler cannot
resolve them both because whichever interface declaration is first is
still incomplete when the second one gets included.
The solution in this case is to forward-declare both classes at the
top of the first (or both) included headers, like this:
@class Status;
@class One;
Then, while the @interface is being processed, the compiler can
resolve things properly.
Regards,
---Chris
I believe I have put forward references in to cover this, but it didn't
solve the problem. The situation I have occurs despite forward
references. (unless I missed one. I've looked and they all seem to be
there)
I have found a fix though. I have moved some includes from the .h
files to the .m files so that when I include a .h file I don't pick up
so many nested includes. This seems to have removed the error.
Specifically I had
Many.m includes Many.h,
Many.h includes ERDocument.h,
ERDocument.h includes Hires.h,
Hires.h includes Many.h
Now I have
Many.m includes Many.h AND ERDocument.h,
ERDocument.h includes Hires.h,
Hires.h includes Many.h
Note that in the first case the sequence returns to item 2 and goes
around again, but in the second case there is no loop.
This now compiles OK.
Denis
On Mar 1, 2004, at 12:33 PM, Denis Stanton wrote:
Is there a problem in Xcode 1.1's handling of #include where classes
are mutually dependent ?
I have written about 20 classes. There are many dependencies so each
.h file contains one or more #include statements. In some cases
these could form loops. so aaa.h includes bbb.h, bbb.h includes ccc.h
and ccc.h includes aaa.h
I have had this compiling satisfactory, but now I've added one more
file and I'm getting a compile error message
"error: cannot find interface declaration for `One', superclass of
`Status'"
I can see that Status.m has the line #include "Status.h", and
Status.h has #include "One.h" so the error doesn't make sense to me.
I notice that in the error message it lists the nested includes and I
can see that One.h has already been found once, before it is reported
as not found. I wonder if the compiler could have a bug in that it
doesn't load One.h a second time because it has already seen it, and
then complains that it has not been found.
Building target myApplication with build style Development
(optimization:level 0, debug-symbols:on) (1 error)
Compiling ERDocument.m
Compiling ERMainWindowController.m
Compiling ERBookingController.m
Compiling Agent.m (1 error)
In file included from
/Users/denisstanton/Projects/myApplication/Agent.m:9:
In file included from
/Users/denisstanton/Projects/myApplication/Agent.h:11,
In file included from
/Users/denisstanton/Projects/myApplication/One.h:11,
In file included from
/Users/denisstanton/Projects/myApplication/ERDocument.h:11,
In file included rom
/Users/denisstanton/Projects/myApplication/
ERMainWindowController.h:11,
In file included from
/Users/denisstanton/Projects/myApplication/Statuss.h:13,
error: cannot find interface declaration for `One',
superclass of `Status'
Am I being stupid, or is there a problem with Xcode? I know from
experience elsewhere that most "bugs" reported by beginners are
actually user error.
Denis
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
Denis Stanton
email@hidden
Home: +64 9 533 0391
mobile: +64 21 1433622
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.