inconsistent 'const' in exec{l,v}.

Carlos O'Donell carlos@systemhalted.org
Thu Nov 17 23:41:00 GMT 2011


2011/11/17 Mark Brown <bmark@us.ibm.com>:
>> i've noticed that manual describes variable number of 'const char*'
>> arguments for execl()
>> and array of non-const arguments for execv(). is it a bug or an
>> intelligent design?
>> imho it should be declared as 'const char* const argv[]'.
>
> I'll refer you to the POSIX spec (online at
> http://pubs.opengroup.org/onlinepubs/9699919799/nframe.html ) for
> how the exec* functions are specified.

C has no notion of "constant data" just that "the contents pointed to
by the pointer won't change" and "the location pointed to by this
pointer won't change" (See 6.7.5.1.3 in ISO C99).

Therefore the POSIX standard, as explained in the Open Group
description, has to choose the best option keeping in mind existing
code.

Specifying the function using "const char* const argv[]" as you
suggest would break existing code by requiring a cast and still
doesn't specify exactly what is intended by the interface and which
can't be expressed in C anyway.

Cheers,
Carlos.



More information about the Libc-help mailing list