I'd advise against calling that `main`, but name-mangling probably 
come into place, then putting some kind of "decorator" on it may
have it invoked from the 'actual main'.

Implementation-wise, this would require some way to pass the overly-large
argument set (ARG_MAX include both argv and environ btw) to the new
program - this can be done using anonymous pipe or memory-mapped file,
or some certain implementation-specific method (e.g. opening a process
as a file descriptor in FreeBSD, I'm not sure whether it can be
used for this purpose). The 'actual main' can then pick up those
argument set, construct the arguments and the environment class objects,
then pass it to the 'identifier-mangled' `main`.

The 'actual main' in most implementations are actually an ordinary function
that's invoked by the entry point defined in a special object file -
this object file is injected into the program during linking (I think
they may be called "crt[01in].o" or something). This entry point
can in theory skip calling the so-called 'actual main', and invoke the
'identifier-mangled' `main` directly instead.

> 2025年7月24日 23:51,Hans Åberg <[email protected]> 写道:
> 
> OK. Thanks.
> 
> I suggested a general form, which should allow one to experiment with C++ 
> types:
>  template<class Arg, class Env>
>  int main(Arg args, Env envs);
> where Arg, Env are types T with constructors of the form
>  T(char** first, char** last)
> 
> 
>> On 24 Jul 2025, at 17:09, Niu Danny <[email protected]> wrote:
>> 
>> 
>> You can specify a path to a configuration file, that's something a typical 
>> Unix daemon do. You can allow multiple such options to combine multiple 
>> configs that specify different parts of the program behavior. There's 
>> otherwise no way around the ARG_MAX limit, unless you alter kernel 
>> configurations - you usually don't have to re-compile the kernel, but you'll 
>> do have to reboot.
>> 
>> ________________________________________
>> 发件人: [email protected] <[email protected]> 代表 Hans 
>> Åberg via austin-group-l at The Open Group <[email protected]>
>> 发送时间: 2025年7月24日 21:24
>> 收件人: [email protected]
>> 主题: Long command line arguments
>> 
>> I seek some inputs on the practice of using long command lines, like in the 
>> link below. The issue came up on the C++ standardization list, over concerns 
>> when admitting C++ types as arguments in the function “main”.
>> 
>> https://stackoverflow.com/questions/33051108/how-to-get-around-the-linux-too-many-arguments-limit/33278482
>> 
>> 
>> 
> 


  • Long command line argumen... Hans Åberg via austin-group-l at The Open Group
    • 回复: Long command lin... Niu Danny via austin-group-l at The Open Group
      • Re: Long command... Hans Åberg via austin-group-l at The Open Group
        • Re: Long com... Niu Danny via austin-group-l at The Open Group
          • Re: Long... Hans Åberg via austin-group-l at The Open Group
        • Re: Long com... Hans Åberg via austin-group-l at The Open Group
          • Re: Long... Niu Danny via austin-group-l at The Open Group
            • Re:... Hans Åberg via austin-group-l at The Open Group
              • ... Niu Danny via austin-group-l at The Open Group
                • ... Hans Åberg via austin-group-l at The Open Group
              • ... Guy Harris via austin-group-l at The Open Group
                • ... Hans Åberg via austin-group-l at The Open Group
                • ... Guy Harris via austin-group-l at The Open Group

Reply via email to