473,394 Members | 1,766 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,394 software developers and data experts.

const char* argv


Why isn't:

int main(int argc, char* argv[]) { /* ... */ }
as:
int main(int argc, const char* argv[])
I assume you can't edit the strings which argv points to. . . right ?
-JKop
Jul 22 '05 #1
10 8695

"JKop" <NU**@NULL.NULL> wrote in message >
Why isn't:

int main(int argc, char* argv[]) { /* ... */ }
as:
int main(int argc, const char* argv[])
I assume you can't edit the strings which argv points to. . . right ?


No. This is a quote from C99 -
"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."

Sharad
Jul 22 '05 #2
No. This is a quote from C99 -
"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."

This is a genuine question: What has that to do with C++? I take it that C99
is some sort of... other dialect of C or C++ . . . ?

-JKop
Jul 22 '05 #3

"JKop" <NU**@NULL.NULL> wrote in message
No. This is a quote from C99 -
"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."

This is a genuine question: What has that to do with C++? I take it that

C99 is some sort of... other dialect of C or C++ . . . ?


Nah...C++ is based on C90 actually. You can find references to C subclauses
in the C++ Standard. C99 is the more recent revision of the C Standard, I
made a quote from that. AFAIK C++ inherits it the same way as C does in this
regard, not very sure though.

Sharad
Jul 22 '05 #4
JKop wrote:
No. This is a quote from C99 -
"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."


This is a genuine question: What has that to do with C++? I take it that C99
is some sort of... other dialect of C or C++ . . . ?


It is the 1999 version of the C standard.

Hmm. The C++ standard doesn't seem to say anything about it. But since
this mechanism is pretty much equivalent in C++ to the C mechanism, I guess
that it is the same in C++.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #5

"JKop" <NU**@NULL.NULL> wrote in message
news:59*******************@news.indigo.ie...

Why isn't:

int main(int argc, char* argv[]) { /* ... */ }
as:
int main(int argc, const char* argv[])
Because the 'argv[]' strings are modifiable.


I assume you can't edit the strings which argv points to. . . right ?


Wrong.

-Mike
Jul 22 '05 #6
In article <5X****************@newsread3.news.pas.earthlink.n et>,
mk******@mkwahler.net says...
I assume you can't edit the strings which argv points to. . . right ?


Wrong.

I would say, this depends on the Startup-Code. Especially, when you're
on an embedded system.
Jul 22 '05 #7
JKop wrote:
Why isn't:

int main(int argc, char* argv[]) { /* ... */ }
as:
int main(int argc, const char* argv[])
I assume you can't edit the strings which argv points to. . . right ?


C++98 retains C90 as a subset except of the case where otherwise is
mentioned.

Now I think that the C90 text should be included in C++98, but that's
another issue.
In C90 it is mentioned:
"Program startup"

The function called at program startup is named main . The
implementation declares no prototype for this function. It can be
defined with no parameters:

int main(void) { /*...*/ }

or with two parameters (referred to here as argc and argv , though any
names may be used, as they are local to the function in which they are
declared):

int main(int argc, char *argv[]) { /*...*/ }
If they are defined, the parameters to the main function shall obey
the following constraints:

* The value of argc shall be nonnegative.

* argv[argc] shall be a null pointer.

* If the value of argc is greater than zero, the array members
argv[0] through argv[argc-1] inclusive shall contain pointers to
strings, which are given implementation-defined values by the host
environment prior to program startup. The intent is to supply to the
program information determined prior to program startup from elsewhere
in the hosted environment. If the host environment is not capable of
supplying strings with letters in both upper-case and lower-case, the
implementation shall ensure that the strings are received in
lower-case.

* If the value of argc is greater than zero, the string pointed to by
argv[0] represents the program name ;argv[0][0] shall be the null
character if the program name is not available from the host
environment. If the value of argc is greater than one, the strings
pointed to by argv[1] through argv[argc-1] represent the program
parameters .

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

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 22 '05 #8

"Michael Bruschkewitz" <br*****@gmx.net> wrote in message
news:MP************************@news.compuserve.de ...
In article <5X****************@newsread3.news.pas.earthlink.n et>,
mk******@mkwahler.net says...
I assume you can't edit the strings which argv points to. . . right ?


Wrong.

I would say, this depends on the Startup-Code. Especially, when you're
on an embedded system.


Well, if the implementation for the embedded system is not
a hosted implementation (imo typical of an embedded implementation),
yes, it depends. On such a system, A 'main()' is not required
at all. So any requirements about 'main()' refer to a hosted
implementation.

-Mike
Jul 22 '05 #9
In article <sb***************@newsread3.news.pas.earthlink.ne t>,
mk******@mkwahler.net says...
Well, if the implementation for the embedded system is not
a hosted implementation (imo typical of an embedded implementation),
yes, it depends. On such a system, A 'main()' is not required
at all. So any requirements about 'main()' refer to a hosted
implementation.

I never needed main on the embedded system, it always used other ways to
find the startup function(s). But it would be possible.
I've my copy of the standard not at hand, so I currently don't know what
the standard says.
However, I don't think it is very recommendable to modify the strings
from argv, or the pointers inside argv. To be safe, you can't increase
the amount of memory needed for the pointers nor the strings. So, the
modification is limited to the cases where the number of the strings or
the length of the strings decreases.
I would avoid such potential pitfalls by a clear solution without
modifying argv. For example, convert argc,argv to
std::vector<std::string> and modify this. If you're allowed to use STL.
Especially, because startup is not a performance issue.
Also, it will always be possible to assign a new value to argv itself.

Regards,
Michael B.
Jul 22 '05 #10
In C90 it is mentioned:

It's in the C++ Standard also.
-JKop
Jul 22 '05 #11

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

Similar topics

3
by: Steven T. Hatton | last post by:
Sorry about the big code dump. I tried to get it down to the minimum required to demonstrate the problem. Although this is all done with GNU, I believe the problem I'm having may be more general. ...
5
by: Brad Moore | last post by:
Hey all, I'm getting the following compiler error from my code. I was wondering if anyone could help me understand the concept behind it (I actually did try and compile this degenerate...
16
by: herbertF | last post by:
Hi guys, In a program (not my own) I encountered the declaration of a constant pointer to an array consisting of two other const pointers to arrays. Not quite sure why they do it so complicated,...
5
by: sugaray | last post by:
I wrote a short code as shown below for experiment purpose, It is successfully compilable, yet I found the piece I wrote even confused myself with the consts and the asterisks, and which brought...
10
by: kevin.hall | last post by:
GCC 3.3 and MSVS 6.0 have no problem converting char* to const char* (not even a warning), but MS's WinCE compiler generated an error complained that this was not possible. MS's WinCE compiler did...
7
by: Eric | last post by:
Hi For this code, int getopt (int argc, char *const argv, const char *opts) what does the "char *const argv" mean? Does it equal to "char **const argv"? Or "char *const *argv"? Which is the...
7
by: Martin | last post by:
When referring to the conforming declaration for main, Lint displays Info 818: Pointer parameter 'argv' (line 3) could be declared as pointing to const Presumably it's saying that the...
9
by: jorba101 | last post by:
On my platform, I see that if I do following: void myFunc( const char *myArg ) { char **argv; argv = &myArg; createTask( ....., argv, .... );
35
by: Sean Farrow | last post by:
Hi: What is best and safest way of converting a char* to a const char *? Can I use const_cast? Cheers Sean.
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.