220 14741 <5124499.Y4MVqN9qgV@tjmaciei-mobl4> article
Path: news.gmane.org!not-for-mail
From: Thiago Macieira <thiago@macieira.org>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Allow const-qualified "argv"
Date: Tue, 25 Nov 2014 19:31:29 -0800
Lines: 82
Approved: news@gmane.org
Message-ID: <5124499.Y4MVqN9qgV@tjmaciei-mobl4>
References: <f6d3621a-5e00-432e-a3f6-18e0ad946bce@isocpp.org> <5749465.k8kpGYc6nD@tjmaciei-mobl4> <c397301b-d7f5-43d0-8a9e-62945c4209af@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
X-Trace: ger.gmane.org 1416972699 30714 80.91.229.3 (26 Nov 2014 03:31:39 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 26 Nov 2014 03:31:39 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCB4TK757YBRBFMT2WRQKGQEQP7XW4Q@isocpp.org Wed Nov 26 04:31:34 2014
Return-path: <std-proposals+bncBCB4TK757YBRBFMT2WRQKGQEQP7XW4Q@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ee0-f69.google.com ([74.125.83.69])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCB4TK757YBRBFMT2WRQKGQEQP7XW4Q@isocpp.org>)
	id 1XtTKH-0001w6-UQ
	for gclcip-std-proposals@m.gmane.org; Wed, 26 Nov 2014 04:31:34 +0100
Original-Received: by mail-ee0-f69.google.com with SMTP id d49sf1403125eek.4
        for <gclcip-std-proposals@m.gmane.org>; Tue, 25 Nov 2014 19:31:33 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:to:subject:date:message-id:user-agent
         :in-reply-to:references:mime-version:content-type:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=UU8A+E/QT6Td66AxlyI+gTY8EZrTRYwRwpzwiUieZ78=;
        b=M1+OPTugJ99FZj9hqACOd2VC5ZiTXuNdyzmOL3zJpDXjO7wem7f1on+OGRneHsFpWv
         FpolJWljGgQhXf0KmNXMZtKWEIciUw77wYijv/eeYY1BDTqF+yVOhgIWlzQVuVSdwMy7
         AgCnTrtybHjx07RlycNBJHDCLgF7RQqbqzDZGO/hS9j2QvVEyAHUJyBXzwfLGgSEUNI6
         VOgKb3bxltGSNl1a4BCGpmYliZv996DsoBqs8B6xdTWLKWAwABTys/ZL0uVdfo2mX2Lc
         UsWMBItE6JoqhYI5dJnMctsqpfjJDsjAu/bfsjAXXSDYM1djQy3hxuGcClGjSiPEN2R1
         5hBg==
X-Gm-Message-State: ALoCoQmA35mFB8QXX1ftsdEoUjiQvUdnfW8L7nPY/z4EgcrC3cN5xCw02BSS39kcyviLcpBrovWN
X-Received: by 10.112.154.194 with SMTP id vq2mr2993836lbb.10.1416972693637;
        Tue, 25 Nov 2014 19:31:33 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.180.83.133 with SMTP id q5ls710668wiy.31.canary; Tue, 25 Nov
 2014 19:31:32 -0800 (PST)
X-Received: by 10.180.81.102 with SMTP id z6mr37018471wix.69.1416972692830;
        Tue, 25 Nov 2014 19:31:32 -0800 (PST)
Original-Received: from gondolin.macieira.info (gondolin.macieira.info. [78.47.120.188])
        by mx.google.com with ESMTP id gd8si20110265wib.41.2014.11.25.19.31.32
        for <std-proposals@isocpp.org>;
        Tue, 25 Nov 2014 19:31:32 -0800 (PST)
Received-SPF: pass (google.com: domain of thiago@macieira.org designates 78.47.120.188 as permitted sender) client-ip=78.47.120.188;
Original-Received: from tjmaciei-mobl4.localnet (unknown [192.55.54.40])
	by gondolin.macieira.info (Postfix) with ESMTPSA id 0E3B011B4B0
	for <std-proposals@isocpp.org>; Tue, 25 Nov 2014 19:31:32 -0800 (PST)
User-Agent: KMail/4.14.2 (Linux/3.11.10-21-desktop; KDE/4.14.2; x86_64; ; )
In-Reply-To: <c397301b-d7f5-43d0-8a9e-62945c4209af@isocpp.org>
X-Original-Sender: thiago@macieira.org
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of thiago@macieira.org designates 78.47.120.188 as permitted sender) smtp.mail=thiago@macieira.org
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:14741
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/14741>

On Tuesday 25 November 2014 12:36:35 Myriachan wrote:
> Visual Studio already has a wmain(), which is why I pointed this out.  Note
> that in Windows, main() is a compiler concept, not a system one; this is
> comparable to "start" of crt0.o on the major POSIX systems.
> 
> extern "C" int __cdecl wmain();
> extern "C" int __cdecl wmain(int argc, wchar_t **argv);
> extern "C" int __cdecl wmain(int argc, wchar_t **argv, wchar_t **envp);

Actually, it's a regular function. The real entry point is WinMain and the 
runtime needs to split the arguments into argv before proceeding.

> 
> > Actually, the only way this would work is if the compiler emitted an
> > external
> > symbol called "main" whenever it saw one of those four functions.
> 
> > Unfortunately, it doesn't solve this problem:

> How Microsoft's compiler works is that the compiler emits a linker
> directive into the .obj file if it sees a function named ::wmain defined.
> Specifically, it emits /ENTRY:wmainCRTStartup to change the entry point of
> the module to wmainCRTStartup().  wmainCRTStartup() is the "start"
> equivalent in Windows.  mainCRTStartup(), the default, calls main(), and
> wmainCRTStartup() calls wmain().  mainCRTStartup() handles any conversion
> if required.  If c16main() or c32main() existed, they likely would be based
> upon a similar model.  wmainCRTStartup would likely use a hack to call
> c16main so as to avoid a 4th copy of the startup code.

Microsoft's solution would not work for everyone. It implies having control 
over the linker, which is not always the case for C++ compiler writers. Hence 
what I said that the solution is to always have a "main", regardless of what 
the user typed.

> > And all along it would allocate more memory for the conversions (well,
> > the
> > 
> > > UCS-4 to UTF-16 conversion can be done in-place).
> > 
> > This still requires allocating memory, which may fail. And it requires
> > knowing
> > what the system locale is in order to convert from 8-bit, before the first
> > line
> > of user code...
> 
> Systems generally have code before either main() or the global constructors
> anyway.  It's already the case that in Windows, using main() instead of
> wmain() loses information from the command line due to the system code
> page/locale.  Windows has to allocate memory for the argv buffer
> regardless, because Windows has command lines as a singe string, and the C
> runtime library needs to split it up into argv format.
> 
> POSIX systems have less to worry about.

They have the locale to worry about in your proposal. It might imply having to 
load a plugin for iconv() before main() gets run in order to do the 
conversion.

This is not impossible, just way too complex for the benefit.

> Perhaps wmain(), c16main() and c32main() could be optional but recommended
> in the Standard?  In other words, specifying (figuratively), "if these
> entry points do exist, they function as the following...".

Then the standard also needs to define a macro that the compiler will set when 
it does support those alternate entry points, so code can properly decide 
whether to have a c16main() or a plain main().

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

-- 

--- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.
