3 ms·
> It's not "a different type from the same base type", instead, it's a different name for the same type. This is why after much consideration, D uses `alias` i
by WalterBright 4y ago
> It's not "a different type from the same base type", instead, it's a different name for the same type.
This is why after much consideration, D uses `alias` instead of `typedef`. `alias` works for other things, too, like creating an alias for a symbol:
alias sqrt = math.std.sqrt;
x = sqrt(y);
or when you're sick of Java style names:
alias eggs = CookAndEatEggsForBreakfast;
eggs();
Of course, in C you'd use a macro for this. But C macros do not respect scoping, so using them is akin to using a table saw without a face shield.
- Gibbon1 4y agoI feel like 'alias' and 'copy' would be rather easy to add to C. alias bar = foo; // bar is an alias of foo copy baz = foo; // baz is copy of foo Alas we have the small problem of the do nothing standards committee.