LDC / BetterC / _d_run_main
Uknown
sireeshkodali1 at gmail.com
Sat Mar 10 13:09:59 UTC 2018
On Saturday, 10 March 2018 at 12:00:12 UTC, Richard wrote:
> On Saturday, 10 March 2018 at 07:54:33 UTC, Mike Franklin wrote:
>> On Saturday, 10 March 2018 at 02:25:38 UTC, Richard wrote:
> [snip]
> Based on the above this seems to work fine so I'll use this
> since it's the simplest option.
> ```
> extern(C) int main(int argc, char** argv) {
> return d_main();
> }
>
> int d_main() {
> // Do stuff
> }
> ```
You can simplify it further:
```
extern(C) int main(int argc, char** argv {
//Do stuff
}
```
> This compiles but main() is never called btw
> ```
> import core.stdc.stdio;
>
> private alias extern(C) int function(char[][] args)
> MainFuncType;
> extern (C) int _d_run_main(int argc, char **argv, void*
> mainFunc)
> {
> MainFuncType mFunc = cast(MainFuncType) mainFunc;
> return mFunc(null);
> }
>
> int main() {
> // Do stuff
> }
> ```
> I tried compiling with
> ldc2 -defaultlib= -debuglib= -mtriple=thumb-none-linux-eabi
> -mcpu=cortex-m3 --od=. -c -betterC main.d
I think you should not put `-betterC` since you are trying to use
_d_run_main, which is only called when in regular mode.
More information about the Digitalmars-d-learn
mailing list