edA-qa | 5 Sep 11:28

Proposal for Include files/headers

Rather than use the old C style of just #include I would recommend a 
better manner of handling dependencies.

If you watch the C++ standards discussions you'll also realize there 
technically is now no really portable way of using header files, since 
there is a lack of clarity between #include <file> and #include "file".

What would be nice is a Java style import system, which makes it easier 
for new users, and can remove the problem of ordering of dependencies. 
(The #include system should also remain since it has other uses than 
resolving dependencies).

Example:

	#import Math.Matrix	//get a single definition
	#import Http	//get entire namespace

The implementation then needs a resolution system for importing.  This 
works similar to includes files, but there are "Import" directories. 
Each namespace is translated to a directory and filename.  Beforehand 
the compiler can't know whether it is a namespace or a class or symbol, 
so it has to try all possibilities.

So in the above, the searching for the above might look like:

	1. search for: importDirN/Math/Matrix/all.imp
	2. search for: importDirN/Math/Matrix.imp
	3. search for: importDirN/Math/all.imp
	4. end search

In case 4 the compiler generates a warning saying that a general case 
was included rather than a specific case.  This is forward compatbile 
with library changes then.

I used a different extension there (.imp).  This is to say that import 
files aren't quite the say as includes.  Imp files may then freely use 
include files to achieve their definitions.

Also, a .IMP file is guaranteed not to be included more than once.  This 
removes the need for sentries on header files (none of the #ifdef, 
#define,...#endif nonsense)

Additionally, #import provides one extra mechanism, name resolution of 
imported names occurs after all import statements are completed.  This 
means you don't have to worry about circular references, or worrying 
about the specific ordering of include files.

That is, the following is possible:

	<ClassA.imp>
	#import ClassB

	class ClassA {
		ClassB value;
	}

	<ClassB.imp>
	#import ClassA

	class ClassB {
		ClassA* owner;
	}
	
--

-- 
edA-qa mort-ora-y
Idea Architect
http://disemia.com/

-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click

Gmane