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

后端 未结 13 2234
心在旅途
心在旅途 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:51

    By setting it to int, the range is limited to between 1 and INT_MAX inclusive. This will typically mean that no accidental cast or alias will take it out of range from an inadvertent wrap around. It also allows implementations to use the entire negative and 0 range for system specific scenarios.

    Ok, I just made that up. The real reason is that it was just an arbitrary decision that one of the original C language developers made, and nobody really thought that hard about it until now. :)

提交回复
热议问题