In POSIX, can a main(void) recover command line arguments?

In C, is int main(int argc, char *argv[]) really needed to receive program arguments? In other words, when defining the main function with the signature int main(void) , is it possible to recover the program arguments using only POSIX interfaces?

I feel like I'm missing something, seeing that:

  • POSIX defines multiple interfaces to retrieve other process-specific information. For instance, there are interfaces for environment variables (arguably inherited from C99, but also extended with functions like unsetenv() ) and host identification ( gethostid() ).
  • Specific operating systems define "global" ways to retrieve the command line arguments. For instance, Windows supplies the GetCommandLineW and CommandLineToArgvW functions, and HP-UX supplies the global variables __argc_value and __argv_value . Linux has /proc/self/cmdline , which can be parsed into argv and argc .

  • POSIX specifications do not include functions that can retrieve command line arguments. All of the specified functions require, essentially, main() to orchestrate passing argc and argv to be parsed.

    POSIX specifications (IEEE 1003.1, 2013 edition - the current version as I write this) has a section describing the command line syntax used by the Standard Utilities (which are described in the "Shell and Utilities" volume). However, those utilities - naturally enough - would use POSIX functions, so would be implemented with a main(argc, argv) that calls them.

    链接地址: http://www.djcxy.com/p/88968.html

    上一篇: 配置接收器elasticsearch apache

    下一篇: 在POSIX中,可以使用主(void)恢复命令行参数吗?