[cfe-dev] Calling main() is ub based optimizations

James Y Knight via cfe-dev cfe-dev at lists.llvm.org
Mon Nov 14 08:06:30 PST 2016


On Mon, Nov 14, 2016 at 5:48 AM, David Chisnall via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> On 14 Nov 2016, at 09:43, Eric Fiselier via cfe-dev <
> cfe-dev at lists.llvm.org> wrote:
> >
> >
> >
> > On Sat, Nov 12, 2016 at 11:09 AM, Mehdi Amini via cfe-dev <
> cfe-dev at lists.llvm.org> wrote:
> > main is marked as “norecurse” in C++ and not in C:
> >
> > I would be interested in seeing the standardese associated with each
> behavior.
> >
> > /Eric
>
> Indeed.  If I implement main in C++ and call it from C, or implement main
> in C and call it from C++, is it undefined behaviour in both cases?  This
> seems like a very odd inconsistency if I have to know the source language
> for both the caller and callee to determine whether something is UB.
>

I suspect that this restriction in C++ came about in the first place
because some compilers were putting the code for dynamic initialization of
static variables at the beginning of the function called "main", and thus
recursively calling it would rerun the static initialization.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20161114/9361a8c8/attachment.html>


More information about the cfe-dev mailing list