www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Converting #ifdef to version statements.

reply =?ISO-8859-1?Q?Julio_C=E9sar_Carrascal_Urquijo?= writes:
Hi.

I'm porting some headers from C that use #ifdef macros that I'm trying 
to translate to version statements. The macros are #defined in a 
"features.h" file witch is included in the others:

//features.h
#define FEATURE_A
#define FEATURE_B
#define FEATURE_C

//header_a.h
#include <features.h>
#ifdef FEATURE_A
...
#endif


//header_b.h
#include <features.h>
#ifdef FEATURE_B
...
#endif
#ifdef FEATURE_C
...
#endif

The direct translation using "version = FEATURE_A" doesn't work. I 
remember Walter saying some time ago that version definitions like this 
only affected modules imported by the module that defined them. I 
understand why, but in this case I would at least be able to do 
something like:

version (features.FEATURE_A)
{
...
}

So in this case, what should I do? Any one knows a work around this 
limitation?

Thanks
Jan 18 2006
parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Julio César Carrascal Urquijo wrote:

 So in this case, what should I do? Any one knows a work around this 
 limitation?
Include them in the DFLAGS (i.e. set them in your Makefile) --anders
Jan 18 2006
parent reply =?ISO-8859-1?Q?Julio_C=E9sar_Carrascal_Urquijo?= writes:
Isn't there a way to accomplish on source code only? (without modifying 
the command line).

This is a library and I don't want the users to add a bunch of defines 
to the command line each time they link to it.


Anders F Björklund wrote:
 Julio César Carrascal Urquijo wrote:
 
 So in this case, what should I do? Any one knows a work around this 
 limitation?
Include them in the DFLAGS (i.e. set them in your Makefile) --anders
Jan 18 2006
next sibling parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Julio César Carrascal Urquijo wrote:

 Isn't there a way to accomplish on source code only? (without modifying 
 the command line).
I haven't really found any... Walter deliberately wants to keep versions much simpler than #defines. This also means it doesn't work similarly ? I'm afraid I've resorted to copy/paste and other such dirty workarounds. No idea how it would work, if one ever wanted to port e.g. "autoconf" ? --anders
Jan 18 2006
parent =?ISO-8859-1?Q?Julio_C=E9sar_Carrascal_Urquijo?= writes:
I understand and thanks for your help.



Anders F Björklund wrote:
 Julio César Carrascal Urquijo wrote:
 
 Isn't there a way to accomplish on source code only? (without 
 modifying the command line).
I haven't really found any... Walter deliberately wants to keep versions much simpler than #defines. This also means it doesn't work similarly ? I'm afraid I've resorted to copy/paste and other such dirty workarounds. No idea how it would work, if one ever wanted to port e.g. "autoconf" ? --anders
Jan 18 2006
prev sibling parent reply Chris Sauls <ibisbasenji gmail.com> writes:
Julio César Carrascal Urquijo wrote:
 Isn't there a way to accomplish on source code only? (without modifying 
 the command line).
 
 This is a library and I don't want the users to add a bunch of defines 
 to the command line each time they link to it.
Might be time to start using the Build utility then. http://trac.dsource.org/projects/build Of course the downside is that, assuming the library is recompiled by users, they will also need to use Build. Unless Walter randomly decides to make pragma(export_version) a standard D'ism. -- Chris Sauls
Jan 18 2006
parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Chris Sauls wrote:

 Might be time to start using the Build utility then.
 http://trac.dsource.org/projects/build
Build works rather poorly with GDC unfortunately. Or at least it does when I try it on the Mac... --anders
Jan 18 2006