What on earth is std.windows.d?

Don Clugston dac at nospam.com.au
Sun Mar 5 23:52:55 PST 2006


Sean Kelly wrote:
> Don Clugston wrote:
>> jcc7 wrote:
>>>>> Don Clugston wrote:
>>>> I've been inspired to have a go at making a C2D header converter. I 
>>>> know that's been done before, but this one's in D.
>>
>>> Please keep us updated on this. I think the D community is really 
>>> hungry for a
>>> C2D program written in D. I know I'd like to have such a tool in my 
>>> toolbelt.
>>
>> I think this is crucial. We can't possibly maintain D bindings for all 
>> the zillions of C libraries out there, if it's being done manually.
>>
>>> (I'm sure some things will always need to be converted manually, but 
>>> whatever
>>> can be converted automatically lets the humans save their time for more
>>> interesting pursuits.)
>>
>> I think a 100% automatic conversion is practically impossible, 
>> basically because #define is such an ambiguous language construct. eg is
>> #define FOO 1
>> defining a constant int? Or is it a flag for a later #ifdef in this 
>> file? Or in another file?
> 
> The most reliable automatic conversion would probably be to feed 
> everything through a C preprocessor and do macro replacement but for #if 
> (which would be converted to static if).  The downside would be numeric 
> literals littered throughout the headers instead of potentially invalid 
> auto declarations.  I suppose there's no perfect solution :-/

Unfortunately, the preprocessor solution doesn't always work. Some 
macros must be expanded, some must not be.
For example, one file I've converted is littered with things like:

#define DAQmx_Val_Rising                      10280

It's never referenced elsewhere in the file. So, if you run it through a 
preprocessor, it just disappears.
It needs to be converted to:
const DAQmx_Val_Rising = 10280;
(Actually this one really should have been an enum).

Null defines are easy:
#define ABC
this always means ABC will only ever be used in a #ifdef statement, so 
it should never appear in the file. Unfortunately, sometimes you find
#define ABC 1
even though the value of ABC is never used.
It might be possible to do an initial pass through all header files, 
trying to work out the purpose of each #define.
It seems to be very easy to deal with the first 95% of cases; probably 
the last 1% of pathological cases are ten times as difficult as 
everything else combined.



More information about the Digitalmars-d mailing list