Conditional compilation inside asm and enum declarations

Julian Salazar julian at ifeelrandom.com
Mon Jul 13 08:15:22 PDT 2009


Hi, I'm new here to the community but I've been using D for a while now, and 
I have to say that it's a great programming language. I'd like to get 
involved in this community and help shape this language.

I'm just wondering about a minor issue: why are conditional blocks invalid 
within expressions such as enum and asm? I mean, in trivial cases it's fine, 
but in instances where code duplication is a big maintainability nightmare, 
making conditional compilation more flexible would have benefits for 
developers.

Something like (I know it's a trivial example, but you get the point):

asm {
    version(x86) mov EAX, 1;
    else version(x86_64) mov EAX, 2;
}

would trigger an error. Also, though I know enum qualifies as a 
constant/datatype cross, structs and classes are perfectly fine with 
conditional compilation. Couldn't the lexical stuff be changed to support it 
for enum and asm as well?

Also, I noticed that there is no formal specification page for x86-64 inline 
assembly. You define a predefined version identifier such as 
D_InlineAsm_X86_64, but you don't define registers and instructions 
pertaining to it. In GDC for example, using the RAX register in the D inline 
ASM syntax is invalid. Not sure what the case is in LDC (they probably do 
implement it for x86-64), and I know DMD does not have a 64-bit version, but 
the spec should at least have a definition for compilers that do implement 
64-bit support.

Thanks for your time,
- Julian 




More information about the Digitalmars-d mailing list