C changing the value in initialized read only data

Discussion in 'C Programming' started by mohan, Nov 9, 2003.

  1. mohan

    mohan Guest

    According to page 20 & 21 "Unix Network Proramming" W>Richard Stevens
    the vale of argv and argc are in initialized read-only data. This
    must mean that this is not changable inside the program ( Correct me
    if I am wrong) But when I executed the program the result was
    different

    Program
    ========


    int main(int argc, char *argv[])
    {
    printf("the value of argv[0] is %s\n",argv[0]);
    printf("\n\t\t changing the same \n\n");
    argv[0]="test me";
    printf("\n\n\a after change value of argv[0] is %s\n\n",argv[0]);
    }

    output
    ========

    the value of argv[0] is ./mainchng
    changing the same
    after change the value of argv[0] is test me



    Or have i misunderstood the docs
     
    mohan, Nov 9, 2003
    #1
    1. Advertising

  2. In article <>, mohan wrote:
    > According to page 20 & 21 "Unix Network Proramming" W>Richard Stevens
    > the vale of argv and argc are in initialized read-only data. This


    It would be better if you looked in the standard.

    5.1.2.2.1 of C99 says

    [...] The parameters argc and argv and the strings pointed
    to by the argv array shall be modifiable by the program, and
    retain their last-stored values between program startup and
    program termination.


    The printed copy of the standard (ISBN 0-470-84573-2) was 10 GBP
    cheaper than one of the networking books by Stevens last time I
    looked.


    --
    Andreas Kähäri
     
    Andreas Kahari, Nov 9, 2003
    #2
    1. Advertising

  3. [OT] Re: C changing the value in initialized read only data

    In article <>, Andreas Kahari wrote:
    > In article <>, mohan wrote:
    >> According to page 20 & 21 "Unix Network Proramming" W>Richard Stevens
    >> the vale of argv and argc are in initialized read-only data. This


    Oh, and those pages contain Unix history diagrams in my copy of
    "Unix Network programming, volume 1", and a discussion about
    POSIX IPC in volume 2... Where did you in fact read that?

    --
    Andreas Kähäri
     
    Andreas Kahari, Nov 9, 2003
    #3
    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. keithb
    Replies:
    2
    Views:
    8,072
    keithb
    Jun 7, 2006
  2. mohan
    Replies:
    2
    Views:
    316
    Richard Bos
    Nov 10, 2003
  3. Chad
    Replies:
    3
    Views:
    398
    Ben Bacarisse
    Sep 18, 2007
  4. ww
    Replies:
    4
    Views:
    413
    James Kanze
    Oct 26, 2007
  5. Replies:
    11
    Views:
    490
    Phil Carmody
    Apr 21, 2009
Loading...

Share This Page