Annoying prototypes for execv* functions in V.4 <sys/unistd.h>

Doug Gwyn gwyn at smoke.brl.mil
Fri Feb 1 04:58:58 AEST 1991


In article <3598 at lupine.NCD.COM> rfg at lupine.ncd.com (Ron Guilmette) writes:
>I'm fairly sure that these declarations should be changed to:
>extern int execv(const char *, const char *const *);
>extern int execve(const char *, const char *const *, const char *const *);
>extern int execvp(const char *, const char *const *);

Unfortunately there is no "right" way to do this.  Pointer-to-const has
special meaning in function parameter declarations, not quite in line
with the meaning in other forms of declaration.  In particular, type
compatibility checking will approve of passing a pointer to non-const
at the "first" level, but not at the second level of referencing.  Thus
the common usage
	char *args[] = { "prog", "arg1", NULL };
	execv( args[0], args );
would cause an "incompatible types for second argument" diagnostic,
were <unistd.h> (what is this "sys/" prefix?) to provide the additional
"const"s that you suggest.  You can legitimately consider this a
technical deficiency in the C standard if you wish; we simply couldn't
figure out an acceptable way to specify what one would really want for
this and therefore just fixed up the spec for the top level of
referencing.



More information about the Comp.bugs.sys5 mailing list