C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Floating an idea: int main(std::span<std::string_view> args)

From: Richard Hodges <hodges.r_at_[hidden]>
Date: Mon, 9 Sep 2024 08:09:07 +0200
On Sat, 7 Sept 2024 at 17:37, Jeremy Rifkin via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Hello,
>
> I'd like to propose adding int main(std::span<std::string_view> args) as
> a standard signature for main.
>

This would cause a regression in functionality.

The signature for main is: int* main(*int argc*,* char* argv[]*)*

argv is a mutable array of string pointers. Existing programs take
advantage of this when parsing program arguments. They re-order the
pointers in order to group options and trailing arguments.

The proposed change would break all these programs that have worked well
for something like 40 years.

Allowing access to command line arguments in places other than main
(mentioned further down the thread) is a bad idea precisely because of this
mutability.

If it ain't broke...



>
> Motivation:
> - Modernization
> - Ergonomics
> - Teachability
> - Modern C++ through and through instead of 'what's a char**' and
> 'argv[1] == "--help" is a footgun, beware'
>
> Considerations:
> - There would be slight startup overhead in constructing the
> std::string_views and underlying array of string views, however, this
> would be entirely opt-in
> - It would probably add some implementation complexity
> - This would be an aspect of the core language which depends on the
> standard library. I don't love that, but, there is precedence for this
> sort of thing
> - Direct mutability of the argument contents would be lost
>
> I would make a reference implementation as part of the proposal.
>
>
> Cheers,
> Jeremy
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2024-09-09 06:09:19