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

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

    The Google C++ Style Guide suggests never to use unsigned int types unless you're working with actual bit patterns. Their rationale applies to C as well. Quick summary line:

    ... C's type-promotion scheme causes unsigned types to behave differently than one might expect. ... Don't use an unsigned type.

    This was probably not in the minds of the original creator's of C, but who knows‽

提交回复
热议问题