C++ Logo

std-discussion

Advanced search

Re: Fwd: P0781 on command line arguments and standard entry point.

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Sun, 13 Mar 2022 19:00:07 -0400
On Sun, Mar 13, 2022 at 3:52 PM Thiago Macieira via Std-Discussion
<std-discussion_at_[hidden]> wrote:
>
> On Sunday, 13 March 2022 12:23:41 PDT Farid Mehrabi via Std-Discussion wrote:
> > Basically you need to capture the arguments in a span of pointers. But the
> > accessor functions need to be of strin_view type to minimize risk of
> > misusage. The 'main' function can be put in a header forwarding its
> > parameter to the actual entry point function, which is defined in the only
> > cpp file that includes main header.
>
> Changing from a count + C array to span is easy and can be done in O(1) time.
> Creating string_views is O(n) on the length of the command-line and requires
> O(n) memory on the number of arguments. This is what doomed these types of
> proposals before: everyone agrees that the C interface needs update, but
> raising it up to C++ level meets resistance on just how much work is
> acceptable before we get to main().

Considering that we can have arbitrary numbers of constructors that
execute arbitrary amounts of code pre-main, I can't imagine how a few
strlen calls would be a legitimate problem. It would be opt-in anyway,
so it's not like you're paying for it if you don't want it.

> And then there's Windows.

That's a far more pernicious issue, one that suggests that there
simply be a way to query command line arguments, rather than having
them fed through main.

Received on 2022-03-13 23:00:37