Fixing C-style alias declarations.

Bruno Medeiros via Digitalmars-d digitalmars-d at puremagic.com
Thu Sep 4 08:47:50 PDT 2014


On 20/08/2014 01:05, Brian Schott wrote:
> 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?

They suck don't they?  I empathize with you since I also had to write a 
D parser, and thus had to write parsing for that syntax (I assume that's 
why you dislike it as well).

At first I didn't even notice this syntax existed (I don't think it was 
mentioned in the docs when I was writing the parser), it was only when I 
put the whole source of Phobos in the unit-tests that I noticed it was 
there... :S

-- 
Bruno Medeiros
https://twitter.com/brunodomedeiros


More information about the Digitalmars-d mailing list