Fixing C-style alias declarations.

Brian Schott via Digitalmars-d digitalmars-d at puremagic.com
Tue Aug 19 17:05:04 PDT 2014


No, that's not a typo. "alias" is not meant to be "array" in the 
subject line.

Consider the following code:
---
alias A = int[]; // Ai
alias int B[]; // Ai
alias C = int function(int); // PFiZi
int D(int); // FiZi
alias int E(int); // FiZi
alias int F[], G[]; // test.d(6): Error: multiple declarations
                     // must have the same type, not int[] and 
int[]
---

Most of you are probably confused that line 2 compiles. Well, it 
does. D's
broken support for C-style array declarations is back. Just for 
fun, check line
6. It doesn't compile.

On line 5 you find the kind of code that made me aware of this in 
the first
place. The problem here is that if you apply the same logic that 
transforms line
2's alias declaration into line 1, you end up with line 3, which 
has the wrong
"deco" according to the compiler's output, or "alias C = 
int(int);", which does
not compile. From this I come to line 4, which is really obvious, 
and appears to
be the same as the declaration on line 5. This raises the 
question of why the
"alias" keyword is on this[1] line of core.sys.windows.threadaux. 
This is even
more puzzling when you consider the fact that the only time this 
alias is used
is as "fnNtQuerySystemInformation*". That is, if the syntax on 
line 3 of the
example code was used, fnNtQuerySystemInformation would already 
be a pointer
and the "*" could be dropped from its usage. Can anybody come up 
with a use case
for aliasing a function type but not its pointer type?


More information about the Digitalmars-d mailing list