On POSIX, can there be basic (void) recovery command line arguments?

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 .
+7
c posix command-line-arguments
source share
1 answer

POSIX specifications do not include functions that can extract command line arguments. All of these functions require essentially main() to order the passage of argc and argv for analysis.

The POSIX specifications (IEEE version 1003.1, version 2013 - the current version, as I write it) contains a section describing the command-line syntax used by standard utilities (which are described in the "Gateway and Utilities" volume). However, these utilities will naturally use the POSIX functions, so they will be implemented using main(argc, argv) , which calls them.

+4
source share

All Articles