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,
Kevin 10 3287
I know that converting char* to const char* is just fine. The problem
I'm having is with arrays of strings: "char*[]" to "const char*[]". An
argument parsing library my company uses specifies "const char*[]"
because it does not change the command line parameters. But most
people write main as "int main(int argc, char*argv[])".
Some compilers convert argc to "const char*[]", but others seem
incapable. What's correct? ke********@moti oneng.com wrote: I know that converting char* to const char* is just fine. The problem I'm having is with arrays of strings: "char*[]" to "const char*[]". An argument parsing library my company uses specifies "const char*[]" because it does not change the command line parameters. But most people write main as "int main(int argc, char*argv[])".
Some compilers convert argc to "const char*[]", but others seem incapable. What's correct?
Slow down Kevin, and read what you're writing. Given..
int main(int argc, char *argv[])
...compilers don't convert argc at all. You seem to want to qualify the
second argument to main as..
const char *argv[]
...but it's not your call. The Standard says all that stuff is writable.
I think it's probably a bad idea to write to it but it is legal.
--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
First of all, thank you guys for trying to help me out. I really do
appreciate it. I know very well that noone here has to help me and
that they do it out of their goodwill. Thank you! Slow down Kevin, and read what you're writing.
I hope I'm coming off quick tempered. I was just trying to clarify
things. And apparently I still haven't made things completely clear.
My company's argument parsing library has a function called ParseArgs
of the form:
xxx_error_t ParseArgs(int argc, const char*argv[]);
And from in the main function of our utilities, we write:
int main(int argc, char* argv[])
{
xxx_error_t parse_error = ParseArgs(argc, argv);
/* ... */
}
The copiler error for the WinCE compiler generated an error at the call
to ParseArgs.
I hope this clears things up. Thanks again for the help!
Joe Wright wrote: ke********@moti oneng.com wrote: I know that converting char* to const char* is just fine. The problem I'm having is with arrays of strings: "char*[]" to "const char*[]".
There is a faq on this.
An argument parsing library my company uses specifies "const char*[]" because it does not change the command line parameters. But most people write main as "int main(int argc, char*argv[])".
Some compilers convert argc to "const char*[]", but others seem incapable. What's correct? Slow down Kevin, and read what you're writing. Given..
int main(int argc, char *argv[])
..compilers don't convert argc at all. You seem to want to qualify the second argument to main as..
const char *argv[]
..but it's not your call. The Standard says all that stuff is writable.
It depends what you mean by 'all that stuff'. The standard does not
(itself) give licence for argv[] elements to be writable, just the
strings which the elements point to. Of course, argv itself can be
modifed.
int main(int argc, char **argv)
{
if (*argv) **argv = 0; /* fine */
*argv = 0; /* undefined behaviour */
argv = 0; /* fine */
}
I think it's probably a bad idea to write to it but it is legal.
Can anyone name an implementation where they're not writable?
--
Peter
> There is a faq on this.
Do you mind pointing me to it? The only FAQ item I've ever seen is
about converting non-arrays -- something like char* to const char*.
Thanks again! =D ke********@moti oneng.com wrote: There is a faq on this.
Do you mind pointing me to it? The only FAQ item I've ever seen is about converting non-arrays -- something like char* to const char*. http://www.eskimo.com/~scs/C-faq/q11.10.html
What you're probably missing is that...
int main(int argc, char *argv[])
....is identical to...
int main(int argc, char **argv)
C cannot pass whole arrays, instead it passes pointers to the
first element. Hence, function parameters declared as arrays
are silently treated as pointers.
--
Peter
Many thanks for the link! =) ke********@moti oneng.com writes: Many thanks for the link! =)
What??
Search this newsgroup for "Context, dammit!", and follow the advice.
(You may have to go back a bit; I suspect most of the recent
occurrences are reminders like this one.)
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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)
{
|
by: John Smith |
last post by:
What's wrong with the use of atoi in the following code? Why do I
get the error message:
'atoi' : cannot convert parameter 1 from 'char' to 'const char *'
char cBuffer;
void PushUnique(int);
for(y = 0; y < 9; y++)
|
by: Joachim Schmitz |
last post by:
Hi folks
Is it legal for a C compiler that claims to be conforming to the standard
(c89) to issue an error on the following:
char *foo(const char *s)
{
const char *s;
for (s = src; *s && !(((unsigned char)s) & 0x80); s++)
|
by: Ted Sung |
last post by:
Hi,
I'm trying to call a C function from a DLL. The C function is
declared as
char * function( const char * )
I'm declaring it in C# as follows:
|
by: kaizen |
last post by:
Hi,
i wrote the code in C and compiled in VC++ compiler. at that time it
has thrown the below mentioned error.
error C2664: 'strcpy' : cannot convert parameter 2 from 'char' to
'const char *'
Conversion from integral type to pointer type requires
reinterpret_cast, C-style cast or function-style cast
| |
by: lovecreatesbea... |
last post by:
C stops the conversion from (char **) to (const char **). c-faq.com
sec 11.10 has explanation on this point. But, for example, even the
conversion from (char *) to (const char *) brings the same dangerous
as in the previous conversion. Why the latter simple but dangerous one
is allowed in C?
$ cat f1.c
int main(void)
{
const char c = 'a';
|
by: hamishd |
last post by:
Is this possible? Sorry if this question isn't relevant here.
actually, I'm really trying to convert a unsigned char * to an int
|
by: mihai |
last post by:
Hi,
I have a question regarding the conversion (in c or c++) from char**
to const char**.
The fallowing code refuses :) to compile with g++ (and others):
char **p;
const char **q = static_cast<const char**>(p);
|
by: LuxOcculta |
last post by:
Hello, I need some help..
I have to replace in s1, the string s2 with the string s3. I first found if s2 was a substring in s1, but i dont know what to do from here, I'm lost..
example: s1 = "It is a good day to die", s2 = "die", s3 = "pay up"
=> after execution s1 will be "it is a good day to pay up"
Here's the code for the function:
const char *String_Replace(const char *c, const char *sub, const char *s3)
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
| |
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...
|
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...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |