alias extern(Windows) HRESULT fnNtQuerySystemInformation( uint SystemInformationClass, void* info, uint infoLength, uint* ReturnLength ) nothrow;
This does not match any documented form of alias declaration, yet it is accepted by DMD.
Maybe this was supposed to be
alias fnNtQuerysystemInformation = extern(windows) HRESULT function( uint SystemInformationClass, void* info, uint infoLength, uint* ReturnLength ) nothrow;
Comment #1 by blah38621 — 2014-08-17T02:32:36Z
Your suggested alternative wouldn't do the same as that declaration currently does, because it would be typed as a pointer to a function rather than a function type itself, which is what the mangled type of the alias is.
Comment #2 by blah38621 — 2014-08-17T02:36:15Z
To be more precise, the alias declaration, as output in the JSON is:
"name" : "fnNtQuerySystemInformation",
"deco" : "WNbkPvkPkZi"
Comment #3 by hsteoh — 2014-08-19T00:56:13Z
This looks like the old alias syntax `alias originalSymbol newSymbol;`. For functions, it appears to be following C/C++'s totally counterintuitive pattern of function pointer declaration `returnType (*ptrName)(... /*arguments*/)`. In this case, it appears to be aliasing a function that takes (uint, void*, uint, uint*) arguments and returns HRESULT to the name fnNtQuerySystemInformation.
Comment #4 by andrej.mitrovich — 2014-08-19T07:25:06Z
Note that alias "symbol = extern(spec)" is currently broken and won't set the right specifier (or was that just in the parameter lists? I'm not sure).
Comment #5 by k.hara.pg — 2014-08-19T09:00:03Z
(In reply to briancschott from comment #0)
> alias extern(Windows) HRESULT fnNtQuerySystemInformation( uint
> SystemInformationClass, void* info, uint infoLength, uint* ReturnLength )
> nothrow;
>
> This does not match any documented form of alias declaration, yet it is
> accepted by DMD.
> alias extern(Windows) HRESULT fnNtQuerySystemInformation( uint SystemInformationClass, void* info, uint infoLength, uint* ReturnLength ) nothrow;
No, it's valid in the grammar.
AliasDeclaration:
alias StorageClasses_opt BasicType Declarator
Declarator:
BasicType2_opt Identifier DeclaratorSuffixes_opt
DeclaratorSuffix:
Parameters MemberFunctionAttributes_opt
Parameters:
( ParameterList_opt )
...
And then, the name fnNtQuerySystemInformation will alias a function type:
extern(Windows) HRESULT(uint, void*, uint, uint*) nothrow
Comment #6 by briancschott — 2014-08-19T22:00:41Z
So in other words this is allowed because we're still allowing C-style declarations such as "int a[]".
Comment #7 by briancschott — 2014-08-19T23:17:03Z
alias int a(int), b(int);
test.d(1): Error: multiple declarations must have the same type, not int(int) and int(int)
It's the same stupid thing again!
Comment #8 by nick — 2024-10-19T11:42:52Z
(In reply to Kenji Hara from comment #5)
> No, it's valid in the grammar.
...
> And then, the name fnNtQuerySystemInformation will alias a function type:
>
> extern(Windows) HRESULT(uint, void*, uint, uint*) nothrow
So this was invalid. Also the new alias syntax allows aliasing a function type:
// old
alias extern(Windows) HRESULT fnNtQuerySystemInformation( uint SystemInformationClass, void* info, uint infoLength, uint* ReturnLength ) nothrow;
// new
alias fnNtQuerySystemInformation = extern(Windows) HRESULT(uint SystemInformationClass, void* info, uint infoLength, uint* ReturnLength) nothrow;