Version Identifiers for Platforms / Architectures not supported byDMD

Jonathan M Davis jmdavisProg at gmx.com
Thu Nov 10 14:10:10 PST 2011


On Thursday, November 10, 2011 13:10 kennytm wrote:
> 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.

I'm not completely against the idea. I'm just pointing out that it's more 
restrictive that way and potentially messier in code with a lot of version 
statements. There's no question that the vast majority of people aren't going 
to have an else clause with a static assert when versioning OSes. And it 
wouldn't surprise me if something like 99% of the people who do do it do it 
because Walter pointed out the need to them or someone else who Walter had 
pointed it out to pointed it out to them.

- Jonathan M Davis


More information about the Digitalmars-d mailing list