digitalmars.D.learn - overloading main
- NonNull (9/9) Oct 30 2022 I am linking to a C project with some C already automatically
- Imperatorn (2/11) Oct 30 2022 You should not have multiple mains. Rename it and call it
- NonNull (3/4) Oct 30 2022 Doesn't answer my questions. I wasn't asking for practical, moral
- Imperatorn (2/6) Oct 30 2022 Try to phrase your question more clearly. I'm just stating a fact.
- NonNull (8/16) Oct 30 2022 Doesn't look like a fact. Looks like a judgment. A different
- Adam D Ruppe (25/32) Oct 30 2022 did you put extern(C) on that thing? im p sure it'd allow it then
- NonNull (4/25) Oct 30 2022 Ah, makes sense to limit the possible low level error messages
- Imperatorn (2/7) Oct 31 2022 I thought this was too obvious to say, but apparently not.
I am linking to a C project with some C already automatically translated into D including the C main function `int main(int argc, char** argv){/* ... */}` which I wanted to call from a D main function in a new module. But then I found that the former C main in D will not compile! ldc2 complains that main must only have prototypes as if it is the entry point. So it seems that main cannot be overloaded with a prototype that is not a valid entry point in D. Is this restriction essential? And if not, why make it?
Oct 30 2022
On Sunday, 30 October 2022 at 16:09:54 UTC, NonNull wrote:I am linking to a C project with some C already automatically translated into D including the C main function `int main(int argc, char** argv){/* ... */}` which I wanted to call from a D main function in a new module. But then I found that the former C main in D will not compile! ldc2 complains that main must only have prototypes as if it is the entry point. So it seems that main cannot be overloaded with a prototype that is not a valid entry point in D. Is this restriction essential? And if not, why make it?You should not have multiple mains. Rename it and call it
Oct 30 2022
On Sunday, 30 October 2022 at 16:31:45 UTC, Imperatorn wrote:You should not have multiple mains. Rename it and call itDoesn't answer my questions. I wasn't asking for practical, moral or esthetic advice.
Oct 30 2022
On Sunday, 30 October 2022 at 17:29:25 UTC, NonNull wrote:On Sunday, 30 October 2022 at 16:31:45 UTC, Imperatorn wrote:Try to phrase your question more clearly. I'm just stating a fact.You should not have multiple mains. Rename it and call itDoesn't answer my questions. I wasn't asking for practical, moral or esthetic advice.
Oct 30 2022
On Sunday, 30 October 2022 at 17:41:07 UTC, Imperatorn wrote:On Sunday, 30 October 2022 at 17:29:25 UTC, NonNull wrote:Doesn't look like a fact. Looks like a judgment. A different judgment might be to allow overloads and not have them be an entry point unless they have the signatures identified as such by D. My questions "Is this restriction essential? And if not, why make it?" are asking to justify the judgment you made. Which you did not do. So you have not answered them. Not unclear at all.On Sunday, 30 October 2022 at 16:31:45 UTC, Imperatorn wrote:Try to phrase your question more clearly. I'm just stating a fact.You should not have multiple mains. Rename it and call itDoesn't answer my questions. I wasn't asking for practical, moral or esthetic advice.
Oct 30 2022
On Sunday, 30 October 2022 at 16:09:54 UTC, NonNull wrote:I am linking to a C project with some C already automatically translated into D including the C main function `int main(int argc, char** argv){/* ... */}` which I wanted to call from a D main function in a new module.did you put extern(C) on that thing? im p sure it'd allow it then but.... then it'd be the entry point instead of the D main so i don't think it'd let you get ahead.So it seems that main cannot be overloaded with a prototype that is not a valid entry point in D. Is this restriction essential? And if not, why make it?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).
Oct 30 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.
Oct 30 2022
On Sunday, 30 October 2022 at 23:43:03 UTC, NonNull wrote:On Sunday, 30 October 2022 at 18:24:22 UTC, Adam D Ruppe wrote:I thought this was too obvious to say, but apparently not.[...]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.
Oct 31 2022