Thread overview
[Issue 11008] New: Allow -main switch even if user-defined main function exists
Sep 11, 2013
Kenji Hara
Sep 11, 2013
Jonathan M Davis
Sep 11, 2013
Kenji Hara
Sep 11, 2013
Maxim Fomin
Sep 11, 2013
Rainer Schuetze
September 11, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11008

           Summary: Allow -main switch even if user-defined main function
                    exists
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: k.hara.pg@gmail.com


--- Comment #0 from Kenji Hara <k.hara.pg@gmail.com> 2013-09-10 21:18:51 PDT ---
Currently, if user-defined main() function exists, specifying -main switch will
fail to compile.

// test.d
void main() {}

$ dmd -main -run test
test.d(1): Error: only one main/WinMain/DllMain allowed, -main switch added
another main()

But I think this is unnecessary restriction. Compiler can stop adding "another main" when user-defined main() detected.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 11, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11008


Jonathan M Davis <jmdavisProg@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg@gmx.com


--- Comment #1 from Jonathan M Davis <jmdavisProg@gmx.com> 2013-09-10 21:27:32 PDT ---
It could also be argued that it's misleading if -main works when there's already a main function, because instead of simply running the unit tests, the main is going to do whatever the already included main function does. Giving the user an error alerts them to the fact that they're trying to add a main when there already is one (one which almost certainly doesn't do what they want). So, it seems to me that not having -main error out gains us little and causes problems when someone tries to use -main when they already have a main function defined.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 11, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11008


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX


--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> 2013-09-10 21:49:12 PDT ---
Ok. I withdraw this.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 11, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11008


Maxim Fomin <maxim@maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim@maxim-fomin.ru


--- Comment #3 from Maxim Fomin <maxim@maxim-fomin.ru> 2013-09-10 21:53:07 PDT ---
One way to do this is to introduce separate option, say -fno-main-error which does what was proposed in this enh without screwing current switch.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 11, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11008


thelastmammoth@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |thelastmammoth@gmail.com


--- Comment #4 from thelastmammoth@gmail.com 2013-09-10 22:05:42 PDT ---
(In reply to comment #3)
> One way to do this is to introduce separate option, say -fno-main-error which does what was proposed in this enh without screwing current switch.

(In reply to comment #3)
> One way to do this is to introduce separate option, say -fno-main-error which does what was proposed in this enh without screwing current switch.

something more general and useful would be:

dmd -main=mypck.mymodule.myfunction [...]
which specifies the main function to use.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 11, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11008


Rainer Schuetze <r.sagitario@gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |r.sagitario@gmx.de


--- Comment #5 from Rainer Schuetze <r.sagitario@gmx.de> 2013-09-10 23:42:09 PDT ---
What about something like -emptymain to actually force an empty main function to replace an optionally existing one. That way you'd be be able to run the unittests without executing anything else?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------