473,387 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

C changing the value in initialized read only data

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
Nov 13 '05 #1
2 2926
On 9 Nov 2003 10:22:22 -0800, da********@yahoo.com (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
Nov 13 '05 #2
da********@yahoo.com (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
Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: tornado | last post by:
Hi all, I am pretty new to PHP. I was reading PHP manual and trying out the example from 2nd chapter (A simple Tutorial). When i try to print the variable as given in the example it returns...
20
by: Glenn Venzke | last post by:
I'm writing a class with a method that will accept 1 of 3 items listed in an enum. Is it possible to pass the item name without the enum name in your calling statement? EXAMPLE: public enum...
2
by: mohan | last post by:
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 (...
5
by: John N. | last post by:
Hi All, Here I have a linked list each containing a char and is double linked. Then I have a pointer to an item in that list which is the current insertion point. In this funtion, the user...
49
by: matty | last post by:
Hi, I recently got very confused (well that's my life) about the "undefined" value. I looked in the FAQ and didn't see anything about it. On...
10
by: utab | last post by:
Dear all, Can somebody direct me to some resources on the subject or explain the details in brief? I checked the FAQ but could not find or maybe missed. Regards,
4
by: Mathieu Cartoixa | last post by:
Hi, I have been annoyed in one of my recent projects with a problem related to the explicit implementation of an interface on a value type. I will take an example to show the problem. Say we...
23
by: Jess | last post by:
Hello, I understand the default-initialization happens if we don't initialize an object explicitly. I think for an object of a class type, the value is determined by the constructor, and for...
4
by: Jess | last post by:
Hello, I tried several books to find out the details of object initialization. Unfortunately, I'm still confused by two specific concepts, namely default-initialization and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.