为什么argc是一个“int”(而不是一个“unsigned int”)? [英] Why is argc an 'int' (rather than an 'unsigned int')?

查看:126
本文介绍了为什么argc是一个“int”(而不是一个“unsigned int”)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么命令行参数计数变量(传统上为argc)一个int而不是一个unsigned int?是否有技术原因?

Why is the command line arguments count variable (traditionally "argc") an 'int' instead of an 'unsigned int'? Is there a technical reason for this?

我一直在忽略掉所有签名的无符号比较警告,但从来没有理解为什么它的方式

I've always just ignored it when trying rid of all my signed unsigned comparison warnings, but never understood why it is the way that it is.

推荐答案

原始C语言的这样的事实: default任何变量或参数被定义为类型int ,可能是另一个因素。换句话说,你可以有:

The fact that the original C language was such that by default any variable or argument was defined as type int, is probably another factor. In other words you could have:

  main(argc, char* argv[]);  /* see remark below... */

而不是

int main(int argc, char *argv[]);

编辑:Aaron提醒我们,已经是像

Edit: effectively, as Aaron reminded us, the very original syntax would have been something like

  main(argc, argv) char **argv {... } 

由于原型只是稍后介绍。这大约是在每个人至少记录了至少10小时后,追踪微妙的(而不是那么微妙的)与类型相关的错误。

Since the "prototypes" were only introduced later. That came roughly after everyone had logged a minimum of at least 10 hours chasing subtle (and not so subtle) type-related bugs

这篇关于为什么argc是一个“int”(而不是一个“unsigned int”)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆