What's the difference between argp and getopt?

柔情痞子 提交于 2019-12-08 16:05:08

问题


I think the title is self explanatory. I am making a program and I was wondering what I should use of the two and why.


回答1:


argp may be more flexible / powerful / etc, but getopt is part of the POSIX standard. Thats a choice you've to make based on whether you expect your program to be portable.




回答2:


From the Argp manual:

Argp provides features unavailable in the more commonly used getopt interface. These features include automatically producing output in response to the ‘--help’ and ‘--version’ options, as described in the GNU coding standards. Using argp makes it less likely that programmers will neglect to implement these additional options or keep them up to date.




回答3:


There's not much to choose I don't think. The Argp webpage says this:

Argp provides features unavailable in the more commonly used getopt interface. These features include automatically producing output in response to the ‘--help’ and ‘--version’ options, as described in the GNU coding standards. Using argp makes it less likely that programmers will neglect to implement these additional options or keep them up to date.

Argp also provides the ability to merge several independently defined option parsers into one, mediating conflicts between them and making the result appear seamless. A library can export an argp option parser that user programs might employ in conjunction with their own option parsers, resulting in less work for the user programs. Some programs may use only argument parsers exported by libraries, thereby achieving consistent and efficient option-parsing for abstractions implemented by the libraries.



来源:https://stackoverflow.com/questions/7677562/whats-the-difference-between-argp-and-getopt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!