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: Kyle Moffett <email@hidden>
- Date: Mon, 1 Mar 2004 21:59:32 -0500
On Mar 01, 2004, at 17:02, Denis Stanton wrote:
Hi Allan
Thank you for clarifying this.
Including aaa.h from ccc.h will just be ignored by the compiler (at
least if you use import instead of include) -- as it would otherwise
go into an infinite loop.
My error was in misunderstanding what "will be ignored by the
compiler" means. I though the compiler would ignore the duplicated
request to import because it already had the file, but then it would
be kind enough to use the file it already had. What you have said
confirms my fear. It ignores the reference that would create a loop,
but then complains that the reference was not satisfied. I thought
that such loops were inevitable and therefore the compiler would have
a strategy for them. As has been pointed out elsewhere, placing (most
of) the imports into the .m files, rather than having all my .h files
importing each other avoids the loop situation
My personal preference is to layout my .h files like this:
#ifndef MY_PROJECT_MY_OBJECT_H_
#define MY_PROJECT_MY_OBJECT_H_ 1
#include <some/system/header.h>
#include <other/system/header.h>
@class MyObject;
typedef struct foo foo_t;
/* Other declarations that only need system types */
#include <MyProject/MyOtherObject.h>
struct foo {
int a,b;
double x;
};
@interface MyObject : NSObject {
MyOtherObject *bar;
}
[...snip...]
@end
extern foo_t empty_foo;
#endif /* not MY_PROJECT_MY_OBJECT_H_ */
So, basically:
1) System includes
2) Trivial types and type declarations
3) Non-system includes
4) Non-trivial type definitions
5) Global variables
And all of it is wrapped up in an include once directive.
The idea is that my project's files get declarations and minimal
definitions
of my types, even if they include each other. If I have two project
files,
MyObjectA.h and MyObjectB.h that include each other in their non-system
sections, I am guaranteed to get all the trivial types and declarations
from
both files set up before the non-trivial definitions, no matter which
one is
included first.
Cheers,
Kyle Moffett
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCM/CS/IT/U d- s++: a17 C++++>$ UB/L/X/*++++(+)>$ P+++(++++)>$
L++++(+++) E W++(+) N+++(++) o? K? w--- O? M++ V? PS+() PE+(-) Y+
PGP+++ t+(+++) 5 X R? tv-(--) b++++(++) DI+ D+ G e->++++$ h!*()>++$ r
!y?(-)
------END GEEK CODE BLOCK------
_______________________________________________
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.