overloading main

NonNull non-null at use.startmail.com
Sun Oct 30 23:43:03 UTC 2022


On Sunday, 30 October 2022 at 18:24:22 UTC, Adam D Ruppe wrote:
> it prolly just to keep newbs from making confusing mistakes and 
> getting weird behavior at startup. If there's two mains, which 
> one is the expected entry? Perhaps it could just be the one 
> that matches the permitted signature, and if there isn't one it 
> complains. But how does it know if there is one? Suppose 
> there's module A:
>
> module a;
> int main(int argc, char** argv) {}
>
>
> And module B:
> module b;
> void main() {}
>
>
> They are compiled separately:
>
> dmd -c a.d
> dmd -c b.d
> dmd a.o b.o
>
> Which one is the main you want to use? What if you just did 
> `dmd a.d`, should it error that the prototype is wrong, or just 
> give the user the linker error "could not find D main" when 
> they think they have it right there? (remember the linker 
> doesn't know what D signatures are so it can't print a helpful 
> message to correct the mistake).

Ah, makes sense to limit the possible low level error messages 
with separate compilation because of the linker not knowing D 
signatures. Thanks for the intuition.


More information about the Digitalmars-d-learn mailing list