Log in

TIL main() takes a third argument - Tobin's Lab Notebook [entries|archive|friends|userinfo]
Tobin Fricke's Lab Notebook

[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

TIL main() takes a third argument [Oct. 10th, 2012|11:16 am]
Tobin Fricke's Lab Notebook
[Tags|, , ]

It turns out that the environment pointer is passed to main() as the third argument—I had no idea! This seems like something I must have read once upon a time in something like The Unix Programming Environment but I seem to have forgotten.
/* This program prints out the environment in KEY=VALUE format,
   one variable per line: */

#include <stdio.h>

int main(int argc, char **argv, char **envp) {
  while (*envp) 
    printf("%s\n", *envp++);
  return 0;