Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > type of argc

Reply
Thread Tools

type of argc

 
 
subramanian100in@yahoo.com, India
Guest
Posts: n/a
 
      03-14-2007
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

 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      03-14-2007
http://www.velocityreviews.com/forums/(E-Mail Removed), 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
(E-Mail Removed)lid
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
when i compile the cpp file(cmdargs.cpp) int main(int argc, wchar_t* argv[]) Vinu C++ 9 05-05-2005 04:11 AM
use of argc and argv Claudio Varini C++ 3 10-28-2004 02:52 PM
Re: parameter argc is never used ? Default User C++ 7 04-08-2004 09:36 PM
argc and argv userfriendly C++ 3 03-01-2004 03:12 AM
int main(int argc, char *argv[] ) vs int main(int argc, char **argv ) Hal Styli C Programming 14 01-20-2004 10:00 PM



Advertisments