main() inside a module?

430 views
Skip to first unread message

jvp...@g.rit.edu

unread,
Jul 30, 2014, 4:00:32 PM7/30/14
to mod...@isocpp.org
One feature of #includes that I particularly like is that it allows you to include a generic main() function. Should this also be allowed in modules? I hope so.[1]

#including a main() function is particularly useful in cases where you have N different binaries all following the same basic template. The most obvious example of this is when writing unit tests. A developer might have a whole bunch of separate binaries for testing various projects (or parts of a given project), and all of these should have the same entry point, with the same command-line args, etc. As a developer of a unit test framework, I'd want users of the library to be able to #include (or import) the appropriate file/module and get a main() function for free.

Granted, it would be a simple matter of writing a main() function for each binary that just forwards on to the real implementation inside the module, but that's not required when using #includes, and so it would make it considerably less enticing to migrate to modules in a case like this.

- Jim

[1] Some of this is probably an implementation issue: for instance, Linux is perfectly happy with main() coming from a shared library, however (as far as I know), neither Mac or Windows will allow this.

Gabriel Dos Reis

unread,
Jul 30, 2014, 5:02:43 PM7/30/14
to mod...@isocpp.org

In the N4047 design, main() belongs to the global module; I don’t see a fundamental motivation to have it owned by a particular module other than the global module.

 

--
You received this message because you are subscribed to the Google Groups "SG2 - Modules" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modules+u...@isocpp.org.
To post to this group, send email to mod...@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/modules/.

Reply all
Reply to author
Forward
0 new messages