I wonder what the abbreviation envp
stands for, for example here:
int main(int argc, char **argv, char **envp);
I also wonder what the v
in argv
initially stood for. Was the v
for "value"? Or maybe "vector"?
I wonder what the abbreviation envp
stands for, for example here:
int main(int argc, char **argv, char **envp);
I also wonder what the v
in argv
initially stood for. Was the v
for "value"? Or maybe "vector"?
The meaning is:
argv
stands for argument vectorargc
for argument count, andenvp
for environment pointer.We can discuss about the good or bad naming convention, but it's a historic usage that dates back to the beginning of the C language: B.W.Kernighan and D.Ritchie used already argc
and argv
for main()
in their first edition of The C Programming language in 1978.
The envp
was added later from the UNIX development and is an alternative for using the environ
pointer. I found a reference to it in a book from 1986, but it's certainly even older. It doesn't need a count, because it's null terminated. Note that it is not portable and therefore the use of getenv()
should be preferred.
In Kernighan and Ritchie, The C Programming Language, 1978, argv
is shown in the index, on page 221, as:
argv
argument vector 110
The text on pages 110-114 contains no further indication of the derivation of argc
or argv
, other than their semantics. envp
does not appear in the index.
In the second edition, 1988, the text in the corresponding section, on page 114, says:
… two arguments. The first (conventionally called
argc
, for argument count) is the number of command-line arguments the program was invoked with; the second (argv
, for argument vector) is…
Again in the second edition, envp
does not appear in the index.
The Unix specification, IEEE Std 1003.1-2008, 2016, The Open Group Base Specifications Issue 7, says in the section on environ
, execl
, and related routines:
Some implementations provide a third argument to main() called envp. This is defined as a pointer to the environment.
This is consistent with envp
standing for environment pointer.
From C language spec:
J.5.1 Environment arguments
1 In a hosted environment, themain
function receives a third argument,char *envp[]
, that points to a null-terminated array of pointers to char, each of which points to a string that provides information about the environment for this execution of the program (5.1.2.2.1).
Note that this third argument is not listed in C++ language spec, though some implementations are still fine with it.
I haven't studied the etymology of conventional argument names, so please excuse my speculative answer.
'env' rather obviously means environment or environment variables.
The 'p' in envp could be initialism for parameter(s) or, perhaps pointer(s) referring to the type. Perhaps even environment variables of the Program.
Etymology isn't really important for the meaning of the program, so I recommend not to worry about it too much.