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

c, c++, command-line

Solution

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

Problem

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.

Original source