Version Identifiers for Platforms / Architectures not supported byDMD

kennytm kennytm at gmail.com
Thu Nov 10 13:10:54 PST 2011


Jonathan M Davis <jmdavisProg at gmx.com> wrote:
> On Thursday, November 10, 2011 05:08:03 kennytm wrote:
>> Jonathan M Davis <jmdavisProg at gmx.com> wrote:
>>> On Thursday, November 10, 2011 04:07:43 kennytm wrote:
>>>> Perhaps DMD should generate a warning if a version of platforms does
>>>> not
>>>> have an else clause or that version's else clause's content is not
>>>> another version statement or a static assert.
>>> 
>>> Well, that does get a bit fuzzy. For instance, rather than duplicating
>>> that else clause all over the place in std.file, only the first static
>>> if-else clause has the else with the static assert in it. All of the
>>> others just have the branches that work and don't have an else clause.
>>> If we were to require that there be an else like that, then std.file
>>> wouldn't compile. And while it wouldn't be all that bad to have to put
>>> an else on all of those static-ifs, it _would_ result in unnecessary
>>> code duplication.
>>> 
>>> - Jonathan M Davis
>> 
>> I said version(Platform)s, not static if.
> 
> LOL. Yes. And I meant version(Platform). I obviously had my wires crossed when 
> I wrote that. std.file uses
> 
> version(Posix)
> {}
> else version(Windows)
> {}
> 
> without an else block, except for the first one in the file which _does_ have an 
> else which has a static assert(0) in it. Requiring that all such version 
> blocks had elses would invalidate that approach.
> 
> - Jonathan M Davis

Yes, but imagine there's a non-POSIX non-Windows platform (e.g. an embedded
system), and we make stdio to support it. After we add a
version(NewPlatform) branch to the one containing the static assert, the
compiler can no longer help us  to know some version statement in the
middle may have missed the NewPlatform. 

This is a contrived example, and I agree it would often be too strict, so I
think there should be individual warning switches.


More information about the Digitalmars-d mailing list