type in extern declaration
Paul Backus
snarwin at gmail.com
Mon Sep 20 20:24:23 UTC 2021
On Monday, 20 September 2021 at 20:02:24 UTC, NonNull wrote:
> How do I write the type of a function so as to alias it, and
> use that in an extern(C) declaration?
>
> For example, how do I write the type of an external function
>
> int main2(int argc, char** argv) {
> //
> }
You can create an alias to the type:
```d
alias MainFunc = int(int, char**);
```
However, you can't use that alias to declare a variable, because
variables are not allowed to have function types:
```d
MainFunc main;
// Error: variable `main` cannot be declared to be a function
```
The only way you can declare a function in D is with a [function
declaration.][1]
[1]: https://dlang.org/spec/function.html#FuncDeclaration
More information about the Digitalmars-d-learn
mailing list