By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,331 Members | 1,454 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,331 IT Pros & Developers. It's quick & easy.

type of argc

P: n/a
The C standard specifies that argc value should be non-negative. Given
this, is there any reason for keeping the type of argc in main( ) as
int instead of unsigned int ?

For learning purpose I am asking this.

Thanks

Mar 14 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
su**************@yahoo.com, India wrote:
The C standard specifies that argc value should be non-negative. Given
this, is there any reason for keeping the type of argc in main( ) as
int instead of unsigned int ?
Yes: It would break any existing code that controls the
processing of its arguments by decrementing argc until it
becomes negative. The change therefore carries a risk whose
magnitude is hard to estimate, but which is certainly greater
than zero.

Taking a risk can be justified if the expected benefit
outweighs it, but what is the expected benefit? As far as
I can see, the only gain is the ability to handle more than
32766 command-line arguments with a 16-bit int, or more than
2147483646 with a 32-bit int. IMHO, the value of this gain
would be tiny indeed.

You may wonder why argc wasn't an unsigned int to begin
with, which would have made the "it breaks existing code"
problem disappear. Keep in mind that C was not invented
overnight in one atomic act of creation, but evolved along
the way. The earliest versions of C had no unsigned types
at all, so what we now call signed int was the natural choice
for counters of all kinds. When unsigned types were added,
there was -- then as now -- no compelling reason to break
existing perfectly good code.

--
Eric Sosman
es*****@acm-dot-org.invalid
Mar 14 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.