A Few thoughts on C, C++, and D

Jacob Carlborg via Digitalmars-d digitalmars-d at puremagic.com
Tue May 30 12:12:28 PDT 2017


On 2017-05-30 17:15, Ola Fosheim Grostad wrote:

> That's cool!  How robust is in practice on typical header files (i.e
> zlib and similar)?

I would say ok. I did try to run DStep on zlib.h just now. It got quite 
confused when translating the comments. But disabling that it looked a 
lot better. For example, all #defines which are for constants are 
properly translated to enums (manifest constants). The following macros:

#define deflateInit(strm, level) \
         deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
#define inflateInit(strm) \
         inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
         deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
                       (strategy), ZLIB_VERSION, (int)sizeof(z_stream))
#define inflateInit2(strm, windowBits) \
         inflateInit2_((strm), (windowBits), ZLIB_VERSION, \
                       (int)sizeof(z_stream))
#define inflateBackInit(strm, windowBits, window) \
         inflateBackInit_((strm), (windowBits), (window), \
                       ZLIB_VERSION, (int)sizeof(z_stream))

Are translate to:

extern (D) auto deflateInit(T0, T1)(auto ref T0 strm, auto ref T1 level)
{
     return deflateInit_(strm, level, ZLIB_VERSION, cast(int) 
z_stream.sizeof);
}

extern (D) auto inflateInit(T)(auto ref T strm)
{
     return inflateInit_(strm, ZLIB_VERSION, cast(int) z_stream.sizeof);
}

extern (D) auto deflateInit2(T0, T1, T2, T3, T4, T5)(auto ref T0 strm, 
auto ref T1 level, auto ref T2 method, auto ref T3 windowBits, auto ref 
T4 memLevel, auto ref T5 strategy)
{
     return deflateInit2_(strm, level, method, windowBits, memLevel, 
strategy, ZLIB_VERSION, cast(int) z_stream.sizeof);
}

extern (D) auto inflateInit2(T0, T1)(auto ref T0 strm, auto ref T1 
windowBits)
{
     return inflateInit2_(strm, windowBits, ZLIB_VERSION, cast(int) 
z_stream.sizeof);
}

extern (D) auto inflateBackInit(T0, T1, T2)(auto ref T0 strm, auto ref 
T1 windowBits, auto ref T2 window)
{
     return inflateBackInit_(strm, windowBits, window, ZLIB_VERSION, 
cast(int) z_stream.sizeof);
}

Currently DStep cannot handle #if or #ifdef.

> What were the objections to integration with DMD?

I don't recall exactly, I recommend reading the post I linked to [1].

[1] http://forum.dlang.org/post/ks3kir$1ubq$1@digitalmars.com

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list