Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > C changing the value in initialized read only data

Reply
Thread Tools

C changing the value in initialized read only data

 
 
mohan
Guest
Posts: n/a
 
      11-09-2003
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
========

#include <stdio.h>
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
 
Reply With Quote
 
 
 
 
Jack Klein
Guest
Posts: n/a
 
      11-09-2003
On 9 Nov 2003 10:22:22 -0800, http://www.velocityreviews.com/forums/(E-Mail Removed) (mohan) wrote in
comp.lang.c:

> 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


The C standard does not define anything called "read-only data". I
have not read any of Stevens books, but he has a good reputation.
Perhaps you are taking this out of context.

> Program
> ========
>
> #include <stdio.h>
> 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


--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
 
Reply With Quote
 
 
 
 
Richard Bos
Guest
Posts: n/a
 
      11-10-2003
(E-Mail Removed) (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.


That may be true under UNIX, but it isn't quite true in general.

From the last public draft of the C99 Standard:

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

Note that it doesn't say anything about any pointer members of argv;
only about argv itself, and the strings those members point to. Thus,
you can modify:

- argc;
- argv;
- argv[n][m], for all sensible values of n and m;

- but _not_ argv[n], not even for sensible values of n.

Richard
 
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
Value of Un-initialized Stack Variable in OSX prateek86400@gmail.com C Programming 11 04-21-2009 08:52 PM
why const member, reference member can only be initialized not assigned ww C++ 4 10-26-2007 11:22 AM
Where is the value getting initialized in this case Chad C Programming 3 09-18-2007 05:02 PM
Database file and folder are not read only but error message says it is read only?? keithb ASP .Net 2 06-07-2006 03:40 PM
C changing the value in initialized read only data mohan C Programming 2 11-09-2003 06:54 PM



Advertisments