Re: design problem
Re: design problem
- Subject: Re: design problem
- From: Andy <email@hidden>
- Date: Wed, 13 Feb 2002 21:45:54 -0500
>
As I understand it #import will only import the file if it has not already
>
been imported, so putting #import "A.h" at the top of B.h and #import "B.h"
>
at the top of A.h should not result in an infinite loop of A importing B
>
importing A.
>
>
Could be wrong since I haven't tried it ;-)
>
You're right. It is smarter than #include, but it still doesn't work.
I mispoke, its not so much an infinite loop as a chicken and egg problem.
If both headers import each other, the trouble is the types they define
depend on each other. So for A to be a valid type it has to successfully
import B, but for B to be a valid type it has to successfully import A.
They can't both succeed, so you have classic deadlock which you break by
"forward declaring" (to borrow a C++ term?) using @class. C++ has an
equivalent mechanism.
Not to say you couldn't write a compiler that can work it out (Java !)
but I know for a fact Objective-C/gcc doesn't do it as occassionally I
mess up and do it by accident and spend 20 minutes trying to figure out
what I did wrong :)
You know, in all the years I've used Java (wow 6 - scary!) I've never
ever once wished that it had header files. Oh, sometimes other things
that C has would be nice, but I've never missed header files. (If anyone
is going to bring up compilation speed, IBM jikes and Symantec SJ negate
that argument).
--
AndyT (lordpixel - the cat who walks through walls)
A little bigger on the inside
I think we finally found the killer app for Flash: animated stick men
_______________________________________________
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.