473,806 Members | 2,229 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8728

"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******** ***********@new s.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.earthl ink.net>,
mk******@mkwahl er.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.ne t> wrote in message
news:MP******** *************** *@news.compuser ve.de...
In article <5X************ ****@newsread3. news.pas.earthl ink.net>,
mk******@mkwahl er.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.n ews.pas.earthli nk.net>,
mk******@mkwahl er.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

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

Similar topics

3
2240
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. Someone on the SuSE programming mailing list suggested my problem is that I'm trying to execute a function (I assume he meant the constructor) at compile time. The same source code compile if I don't try to split it up into separate libraries. ...
5
22073
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 example). int foo(const char* argv) { return 0; } int main(int argc, char* argv) {
16
41781
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, but is it legal? Most compilers accept it, but one doesn't recognize the rhs as a constant. What are the requirements for the rhs in the declaration of a const pointer? Is the following program legal C? int main(int argc, char *argv) {
5
1831
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 up three questions to me: 1) will the casting in line 1 affect the rest of the declarations ? 2) what's the difference between line 2 and line 3 3) are there any practical purposes of the usage of any of the three ?
10
3286
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 allow a conversion from char* to const char** though. I'm interested in what the standard would say about this. (I don't have a copy.) Many thanks,
7
8562
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 const? Thanks
7
3518
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 definition could be: int main(int argc, char *const *argv) Why didn't C89 mandate that?
9
3623
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
34616
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
10617
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10364
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10370
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4328
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.