C changing the value in initialized read only data

M

mohan

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
 
A

Andreas Kahari

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.
 
A

Andreas Kahari

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top