Why does `execvp` take a `char *const argv[]`?

前端 未结 1 660
长发绾君心
长发绾君心 2020-12-20 12:04

I\'m wondering if there is a reason between two exec functions differing in const-ness, of if this is just a bug in the Single Unix Spec:

Excerpting fro

相关标签:
1条回答
  • 2020-12-20 12:53

    To quote the page you link:

    The statement about argv[] and envp[] being constants is included to make explicit to future writers of language bindings that these objects are completely constant. Due to a limitation of the ISO C standard, it is not possible to state that idea in standard C. Specifying two levels of const- qualification for the argv[] and envp[] parameters for the exec functions may seem to be the natural choice, given that these functions do not modify either the array of pointers or the characters to which the function points, but this would disallow existing correct code.

    Basically the const qualification on execlp and execvp are completely compatible in the sense that they specify identical limitations on the corresponding arguments.

    0 讨论(0)
提交回复
热议问题