From owner-sc22wg14+sc22wg14-domo2=www.open-std.org@open-std.org  Fri Sep  4 19:26:51 2015
Return-Path: <owner-sc22wg14+sc22wg14-domo2=www.open-std.org@open-std.org>
X-Original-To: sc22wg14-domo2
Delivered-To: sc22wg14-domo2@www.open-std.org
Received: by www.open-std.org (Postfix, from userid 521)
	id 3334935714D; Fri,  4 Sep 2015 19:26:51 +0200 (CEST)
Delivered-To: sc22wg14@open-std.org
Received: from mail-qg0-f51.google.com (mail-qg0-f51.google.com [209.85.192.51])
	(using TLSv1 with cipher RC4-SHA (128/128 bits))
	(No client certificate requested)
	by www.open-std.org (Postfix) with ESMTP id B7EE23568B4
	for <sc22wg14@open-std.org>; Fri,  4 Sep 2015 19:26:50 +0200 (CEST)
Received: by qgt47 with SMTP id 47so21319777qgt.2
        for <sc22wg14@open-std.org>; Fri, 04 Sep 2015 10:26:49 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=message-id:date:from:user-agent:mime-version:to:subject
         :content-type:content-transfer-encoding;
        bh=XOPLaWA6xa+S8wMCH4aZPs8UcbTgRwSLYaTG6FTRQJE=;
        b=VT6I5y13cpM6tffV1h44JSsEtZX7joGRnhJoFMNqLIS/RFDUuw0II92Gxcnj1dbB2D
         i8iXlmYqw35FLFrdxVnHvaq0R8pfgEifWvQhc8+8WbPnxzj/OUTHwGLGrQftxslBWiNv
         AiCjzhQ6SVE5dK3QofocRosJADWoL/bo3WeyL9IXUhX0a7TYXZ1qKEzBJMk7+0ky2GYf
         89UEIDTwyB+Ado0Ii2pb+u/t0lOugwBBT4B7I8XVsrHqmIMOSZUvv8zv1mzhnGQnKx3X
         4A2QdRq8bA7QH4v1ju7MAzaXUK0iNrx+gCOQbpoeMVcxWx/TOxrsRhJMSwPRRQNvPzaQ
         0qSQ==
X-Received: by 10.140.82.18 with SMTP id g18mr6881699qgd.41.1441387609177;
        Fri, 04 Sep 2015 10:26:49 -0700 (PDT)
Received: from [192.168.0.26] (97-122-175-227.hlrn.qwest.net. [97.122.175.227])
        by smtp.gmail.com with ESMTPSA id g20sm769931qge.9.2015.09.04.10.26.47
        for <sc22wg14@open-std.org>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Fri, 04 Sep 2015 10:26:48 -0700 (PDT)
Message-ID: <55E9D456.9040301@gmail.com>
Date: Fri, 04 Sep 2015 11:26:46 -0600
From: Martin Sebor <msebor@gmail.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0
MIME-Version: 1.0
To: "sc22wg14@open-std.org" <sc22wg14@open-std.org>
Subject: valid uses of main
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Sender: owner-sc22wg14@open-std.org
Precedence: bulk

5.1.2.2.2 Program execution says:

   In a hosted environment, a program may use all the functions,
   macros, type definitions, and objects described in the library
   clause (clause 7).

5.1.2.2.3 Program termination the goes on to say:

   If the return type of the main function is a type compatible
   with int, a return from the initial call to the main function
   is equivalent to calling the exit function with the value
   returned by the main function as its argument; ...

Is it correct to interpret the first paragraph as a requirement
on programs (in hosted environments) that they must not call or
otherwise use main, and conversely on (hosted) implementations
that they must diagnose such uses?

I ask because the phrase "initial call to the main function"
suggests that there may be other calls to main besides the one
at program startup.  A similar phrase is also used in 7.21.3
Files: "If the main function returns to its original caller,
all open files are closed..." There also is no mention in
Annex J of programs that call main having undefined behavior.
But this interpretation (i.e., permission to use main) would
then contradict 5.1.2.2.2.

Thanks
Martin

PS For comparison, C++ contains an explicit requirement that

   The function main shall not be used within a program.

obviating the question above for that language.
