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

后端 未结 13 2237
心在旅途
心在旅途 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 02:18

    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... */
    

    rather than

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

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

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

    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

    0 讨论(0)
提交回复
热议问题