In C, int main(int argc, char *argv[]) is it really necessary to get the program arguments? In other words, when defining a main function with an int main(void) signature, is it possible to restore program arguments using only POSIX interfaces?
It seems to me that I'm missing something, seeing that:
- POSIX defines several interfaces for obtaining other information related to a particular process. For example, there are interfaces for environment variables (possibly inherited from C99, but also extended with functions like
unsetenv() ) and host identification ( gethostid() ). - Specific operating systems define "global" ways to get command line arguments. For example, Windows provides the
GetCommandLineW and CommandLineToArgvW , and HP-UX provides the __argc_value and __argv_value global variables. Linux has /proc/self/cmdline , which can be parsed in argv and argc .
c posix command-line-arguments
user824425
source share