stdc autoconfig through precompiling

Fawzi Mohamed fmohamed at mac.com
Thu Jan 29 00:56:05 PST 2009


Stdc has many constants that are hardcoded. This is fragile and ugly to 
port to new platforms.

The c preprocessor normally has always the correct values, and so the 
best thing would be to take them from it.

This is my strategy:
add tango.stdc.constants.* modules.
These modules contains *only* enums and version statements and are 
generated from files that get preprocessed.
In particular the exact command is

cpp -P -C $1 | sed -E -e '1,/xx*  *start  *xx*/ d' -e '/^# [0-9]{1,} 
 *\"/ d' -e 's/__XYX__//g'

basically I preprocess them, get rid of the initial part (before xxx 
start xxx) and remove any __XYX__.

so for example
-------
#include <unistd.h>
xxx start xxx
enum __XYX__STDIN_FILENO  = STDIN_FILENO;
-------
becomes
-------
enum STDIN_FILENO=0;
-------

I think this has still all the power of preprocessor configuration 
(just use a static if to query a constant), is still well packaged and 
self contained.

I began to do the first step toward this, look in the latest tango 
trunk in tango/lib/constants .
At the moment it is not yet used, but I wanted some help from people on 
various platforms: please run the dppAll.sh script and tell me 
problems, suggest improvement (I am interested in particular at the 
resulting files in tango/lib/constants/current, if some constants are 
not defined, if some problems crop up).

Windows is not yet really solved, I was thinking to preprocess them 
once by hand, and then put the files in the tango/lib/constants/win 
directory, and on windows simply copy those files, but if some windows 
guru finds a way to make it work always also on windows please tell me.

I think that it could improve much reliability and ability to use the 
newest features of a system if available without polluting the build 
process with many -version...

I think Sean is taking a "let's wait and see" attitude toward this, 
kind of test it and if it is really good it will go in druntime (Sean 
just tell if misrepresented your opinion).
Anyway that was to say that also phobos users are encouraged to 
contribute if they think that it will be useful...

so help out and suggest improvements, correct errors,...

Fawzi




More information about the Digitalmars-d mailing list