type of argc

Discussion in 'C Programming' started by subramanian100in@yahoo.com, India, Mar 14, 2007.

  1. , India

    , India Guest

    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
    , India, Mar 14, 2007
    #1
    1. Advertising

  2. , India

    Eric Sosman Guest

    , 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
    lid
    Eric Sosman, Mar 14, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. userfriendly

    argc and argv

    userfriendly, Feb 29, 2004, in forum: C++
    Replies:
    3
    Views:
    6,002
    Buster
    Mar 1, 2004
  2. Default User

    Re: parameter argc is never used ?

    Default User, Apr 1, 2004, in forum: C++
    Replies:
    7
    Views:
    397
    Christopher Benson-Manica
    Apr 8, 2004
  3. Claudio Varini

    use of argc and argv

    Claudio Varini, Oct 28, 2004, in forum: C++
    Replies:
    3
    Views:
    2,132
    Howard
    Oct 28, 2004
  4. Vinu
    Replies:
    9
    Views:
    617
  5. Hal Styli
    Replies:
    14
    Views:
    1,629
    Old Wolf
    Jan 20, 2004
Loading...

Share This Page