On 7/21/2024 5:47 PM, Gregory Nutt wrote:
On 7/21/2024 5:38 PM, Nathan Hartman wrote:
Hi Alan,
I think we should have "int main(int argc, const char * argv[])" (added
'const' for argv). Maybe should grep for all instances of main in
our code
and docs and add const? I'm willing to do that.
Let me know,
Nathan
POSIX specifies the required prototype of main at
https://pubs.opengroup.org/onlinepubs/007904975/functions/exec.html
Yes, main() is specified in exec() and other locations refer to the
exec() page for the specification of main().
POSIX does specify the prototype from the standpoint of the OS call
into the application. Applications may, of course, use any form that
they like but the OS must conform to this standard.
Also interesting:
https://stackoverflow.com/questions/5808679/why-is-main-argument-argv-of-type-char-rather-than-const-char
That reference explains where argv must not be const. Basically, it
is not const because it should be modifiable.
Not as good, but to the same point:
https://stackoverflow.com/questions/20558418/why-is-argc-not-a-constant
With at least some compilers you will be an error if argv is const
becuase of pointer mismatch. This is expected POSIX-compliant behavior:
https://cboard.cprogramming.com/c-programming/173878-making-const-char-*-out-argv.html