minwin
Bill Baxter
dnewsgroup at billbaxter.com
Tue Nov 28 21:46:53 PST 2006
Tomas Lindquist Olsen wrote:
> Bill Baxter wrote:
>>
>> Agreed. 'version' is basically just an emasculated special case of
>> 'static if'. 'static if' didn't exist when 'version' was created, but
>> now that it does, I think it would make more sense if version became a
>> kind of static if with access to a special version namespace.
>> 'Windows' should be treated like an alias for true if it is indeed
>> defined, otherwise false, and you should be allowed to do boolean ops
>> with any constant values in your program inside the version statement.
>>
>> --bb
>
> I dont think a version statement should be able to access anything but
> versions. besides that I agree!
I could agree with only versions in version statements, but if so then
there needs to be a way to define new versions from code.
Walter's comment about defining versions for specific bugs is on target,
but it makes no sense to have to specify every possible bug and
workaround on the command line. The common pattern used in most major
cross-platform toolkits that deal with these issues is to have some sort
of platform include that basically does things like:
#ifdef WINDOWS
#define BROKEN_PIPE_IMPLEMENTATION
#define BROKEN_SELECT_IMPLEMENTATION
...etc
#endif
If version acted like an enhanced static if then you could do something
like:
version (Windows) {
const int BROKEN_THIS = 1;
const int BROKEN_THAT = 1;
...
}
version (BROKEN_THIS) {
// workaround code
}
In that case I guess version(/undefined symbol/) should evaluate to false.
If you can't use const ints in version statements, then I think you
really need to have something like:
defversion BROKEN_THIS;
defversion BROKEN_THAT;
And while we're talking about versions, there also needs to be a sane
way to check if the version of the software you're using is greater than
some minimum.
version(COOL_LIB_MAJOR_REV>4 || (COOL_LIB_MINOR_REV > 1)
{
}
or even better something special for version numbers like or
version(COOL_LIB_REV > [4, 1])
version(COOL_LIB_REV > 4.1.0)
Here's wxWidgets version macro for checking the version of wxWidgets
you're compiling with. It should be possible to get the same effect in
D somehow:
/* check if the current version is at least major.minor.release */
#define wxCHECK_VERSION(major,minor,release) \
(wxMAJOR_VERSION > (major) || \
(wxMAJOR_VERSION == (major) && wxMINOR_VERSION > (minor)) || \
(wxMAJOR_VERSION == (major) && wxMINOR_VERSION == (minor) &&
wxRELEASE_NUMBER >= (release)))
Here's the full header that came from: http://tinyurl.com/tzbom
Basically I think you can do all that with static if now. If version
doesn't get some more smarts then I'm betting people will use static if
to accomplish things like the above since it's the only way. And if
people start using static if for version checks, well then what was the
point of version, exactly?
--bb
More information about the Digitalmars-d-announce
mailing list