Question About The First Argument In Main()

Does anybody know why the first parameter to "main()" is a signed integer instead of an unsigned or even a short? Is this a left over consideration put in for backward compatibility or something like that?

I can open a program in a debugger and change the parameter on the stack before the application is executed but it doesn't seem to have an effect on anything even if I do something with the negative value (EDIT: Yes, I did feel stupid testing this, and I did not expect anything to happen. But I felt like I should mention that I did check). It just seems odd to essentially waste half of the variables potential.
Last edited on
From what I've seen, it's fairly common to default to "int" for variables where size is not an issue. This makes it easier to avoid needless compiler warnings about signed/unsigned comparisons and the like.

In fact... at my current job, it's part of the coding standards that you use int and only int for integral types unless you have a very compelling reason to use something else.

As for the application to main... it's extremely unlikely (and possibly even impossible?) for a program to be launched with more than 2^31 options. So int is just fine... there's no need to make it unsigned.

Even if int were only 16 bits wide.. 2^15 is still far more than you'll ever see in any program.

Squeezing out that extra bit is kind of pointless.
Simply being convention makes sense, I've seen that reason used in other places. This was one of those questions buzzing around in my head last night and since it was still there today I thought I would ask. Thanks for the input.
It's not convention, it's for backwards compatibility. Back before C had different types, all types were int.

http://stackoverflow.com/a/1773918/1959975
Topic archived. No new replies allowed.