ParameterIdentifierTuple returns empty strings
Adam D. Ruppe
destructionator at gmail.com
Wed Dec 2 15:40:09 UTC 2020
On Wednesday, 2 December 2020 at 11:46:26 UTC, Andre Pany wrote:
> alias fpt = extern(C) nothrow void function(int a, int b);
Function pointers don't really have parameter names. They are
allowed for user habit and documentation purposes, but the
compiler mostly* ignores them; they aren't actually part of the
formal type.
* I'm pretty sure I've seen some weird cases where it did work
but I can't recall right now.
So this alias erases the names before it does anything with them.
This is useful, if you did like
extern(C) nothrow void foo(int not_a, int not_b);
fpt thing = &something;
That assignment is still allowed because the names are not
considered. Change anything else though and you get a type
mismatch.
Moreover, consider reflection on that. Are Parameters!thing `a,
b` because of the alias, or `not_a, not_b` because of the
function assigned?
Pretty obvious it can't be the latter, because what the variable
actually points to is not known at compile time. But then if it
was the former that'd be kinda weird because it wouldn't match
what you set.
So I think think it is doing the best it can by just not giving
the info.
Now btw if you do want the names off `something`,
ParameterIdentifierTuple!something would give you the not_a,
not_b. Maybe you can use that in your code.
If you pass a thing as an `alias` template parameter, without the
& operator, it retains the names.
More information about the Digitalmars-d-learn
mailing list