Permitted locations of a version condition
Stewart Gordon
smjg_1998 at yahoo.com
Thu Oct 29 20:16:13 PDT 2009
Phil Deets wrote:
> Hello, I looked over the language specification, and I could not
> find any statement which says where version conditions are
> permitted.
Language syntax is generally left to the BNF blocks dotted around the
documentation.
> I assumed that they would be permitted most places that #if would
> be reasonable in C, but evidently that is not true as they do not
> work within enumerations.
That's because D's versioning system isn't a preprocessor.
> I would definitely like the following code to work.
>
> enum Tag
> {
> A, B, C,
> version (5) {
> D, E,
> }
> version (7) {
> F, G,
> }
> // ...
> }
So would I, except that it makes more sense to me to have the trailing
comma after the '}'. Commas separate, unlike semicolons, which terminate.
> Added enumerated values based on versions seems like something that
> would be desirable. I ran into this need when converting a header file
> to D.
>
> Does anyone know where version conditions are and are not allowed
> currently?
They're allowed wherever the grammar expects either a statement or a
declaration.
> Would version conditions within enumerations be a good feature to add to
> D2?
<snip>
Yes.
Stewart.
More information about the Digitalmars-d
mailing list