Importing version identifiers from another file?
    KytoDragon 
    kytodragon at e.mail.de
       
    Mon Apr 11 08:57:12 UTC 2022
    
    
  
I am currently maintaining a port of a c++ library that uses 
conditional compilation to integrate into the users program. e.g.:
config.h (edited by the user of the library)
```
#define USE_MY_ASSERT
void MY_ASSERT(bool expr) {...}
```
library.c
```
include "config.h"
#ifndef USE_MY_ASSERT
     void MY_ASSERT(bool expr) {...} // default implementation
#end
```
Given that static if at top-level has been broken for some time 
(https://issues.dlang.org/show_bug.cgi?id=17883, 
https://issues.dlang.org/show_bug.cgi?id=20905, 
https://issues.dlang.org/show_bug.cgi?id=21171), I tried to use 
version identifiers for this in D:
config.d
```
version = USE_MY_ASSERT;
void MY_ASSERT(bool expr) {...}
```
library.d
```
import config;
version (USE_MY_ASSERT) {} else {
     void MY_ASSERT(bool expr) {...}
}
```
Sadly this results in an identifier conflict, as the version set 
in config.d does not seem to affect library.d. Is there any way 
to import version specifiers from a separate file? I don't want 
to pollute the users build files (dub.json etc.) with dozens of 
versions they need to pass to the compiler.
    
    
More information about the Digitalmars-d-learn
mailing list