4 ms·
While we are at it [0]: > The meanings specified in POSIX.1-2017 for the words shall, should, and may are mandated by ISO/IEC directives. By those directives
by planede 3y ago
While we are at it [0]:
> The meanings specified in POSIX.1-2017 for the words shall, should, and may are mandated by ISO/IEC directives.
By those directives "should" indicates recommendation. [1]
> In POSIX.1-2017, the word should does not usually apply to the implementation, but rather to the application. Thus, the important words regarding implementations are shall, which indicates requirements, and may, which indicates options.
You also have to differentiate between any requirements for the argv argument when passed to one of the exec functions and the argv parameter received in main. Any requirement for the former constrains the application, but requirements for the latter constrains the implementation.
exec is indeed only documented in POSIX and OS specific documentations, but main is also documented in ISO C. Both POSIX and ISO C constrains the argv parameter of main not to be null. They don't require argc > 0 or argv[0] != null.
From [2]:
> [under exec] The argument argv is an array of character pointers to null-terminated strings.
This is a hard requirement, without "should". This implies that argv must not be null itself when passed to exec. This probably gives implementations the freedom to do whatever in this case, POSIX doesn't define the behavior. The requirement for argv[0] (which implies argc > 0) is merely a recommendation.
[0] https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap01.html https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd...
[1] https://www.iso.org/foreword-supplementary-information.html https://www.iso.org/foreword-supplementary-information.html