Why is argc an 'int' (rather than an 'unsigned int')?

后端 未结 13 2244
心在旅途
心在旅途 2021-01-31 01:37

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

13条回答
  •  粉色の甜心
    2021-01-31 01:52

    A few reasons:

    • because it doesn't matter
    • because C did not originally have the unsigned keyword or unsigned integer types
    • because C did not originally check parameter types and did not even have prototypes.
      As a result, it was common practice to not even declare int types, as this was the default.
    • because int was, in a sense, more important back then. Everything was an int. C evolved in part from a language that did not even have types. Every single varable was a word, which is what int originally was used for.

    UPDATE: Jason S asked for sources. I think you can dig all of this (except for "it doesn't matter") out of a paper by dmr which is on line: The Development of the C Language. You may need to look up the earlier languages BCPL and B in the usual places.

提交回复
热议问题