免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1547 | 回复: 1
打印 上一主题 下一主题

请教 getopt_long不能正确识别选项少了参数? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-03-01 15:59 |只看该作者 |倒序浏览
本帖最后由 ljpdxj 于 2012-03-01 16:02 编辑



使用该函数,为何它不能正确识别选项少了参数

比如
./Test --module --compress-method

其中--module是一定需要参数的

这里故意不给--module指定参数,为何它会把--compress-method认为是它的参数。。。。
而不是返回程式想要的冒号:    ? (optstring第一个字符指定为了冒号)

感谢感谢!!!!!!!!!!

man 3 getopt_long:

RETURN VALUE
       If  an option was successfully found, then getopt() returns the option character.  If all command-line options have been parsed, then getopt() returns -1.  If getopt() encounters an option character that was
       not in optstring, then ’?’ is returned. If getopt() encounters an option with a missing argument, then the return value depends on the first character in optstring: if it is ’:’, then ’:’ is returned;  oth-
       erwise ’?’ is returned.

       getopt_long()  and  getopt_long_only()  also return the option character when a short option is recognized.  For a long option, they return val if flag is NULL, and 0 otherwise.  Error and -1 returns are the
       same as for getopt(), plus ’?’ for an ambiguous match or an extraneous parameter.

论坛徽章:
0
2 [报告]
发表于 2012-03-01 16:27 |只看该作者
gcc -o -g /Test.c
居然生成了-g可执行文件...

应该算正常的行为,谢谢~
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP