Search code examples
c++cargvabbreviation

What does envp stand for?


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"?


Solution

  • The meaning is:

    • argv stands for argument vector
    • argc for argument count, and
    • envp 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.