minwin
Sean Kelly
sean at f4.ca
Wed Nov 29 13:45:18 PST 2006
Anders F Björklund wrote:
>
> I'm sure that things would be different if writing new D code,
> and not just porting C/C++ stuff over - which is where I usually
> run into wanting a #ifndef or other similar predefined versions.
> I don't *want* to change the macros, since they're in the API...
Doesn't 'static if' fit the bill here? It supports full expression
logic and is evaluated at compile-time, just like 'version'. In
instances where code is automatically translated to D, I'd probably just
convert #defines to enum or const values and use 'static if' in place of
#if. For manual conversions though, I think a hybrid approach is best.
For example, in converting POSIX headers to D I've noticed that nearly
all the #if blocks are for selecting features determined at an OS
level--the presence of conditions that may vary within an OS is actually
pretty rare. That being the case, it seems reasonable to either version
by OS name or set up more granular version identifiers and pre-select
the appropriate ones in a makefile or global compiler parameter variable.
Sean
More information about the Digitalmars-d-announce
mailing list