473,925 Members | 24,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is char*[] convertible to const char*[]?

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

Nov 15 '05
10 3294
On 26 Aug 2005 14:18:37 -0700, ke********@moti oneng.com wrote:
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.)


You can't convert anything to an array in C, ever. (Although in C99 or
GNUC you can _construct_ an array value with a compound literal.)

If you're talking about passing arguments to a function parameter
declared 'const char * []', remember that such a declaration is
'adjusted' to 'const char * *'. If you try to pass a 'char * []', it
first decays to 'char * *' and then you are trying to convert that as
by assignment to 'const char * *' which isn't allowed, and should be
diagnosed by any compiler. Are you sure you are running each compiler
in a mode (i.e., with options) that tries to conform to the standard?
For gcc try -ansi (or -std=c99 if you prefer) and -pedantic and
preferably -Wall; for MSVC6 /Za /W4, or in the IDE there is a tickbox
somewhere to "disable language extensions".

_With a cast_ the pointer conversion is permitted, and should work --
that is, the conversion itself should work, since the result's target
must have the same alignment requirement, and same representation so
accessing the actual char * as a const char * must work. Using _that_
pointer might be const-unsafe in conjunction with other operations,
which is one reason the 'outer' conversion is not allowed. (This is
frequently asked, but not in the FAQ last I looked; 11.10 just says it
isn't allowed but doesn't explain why.)

- David.Thompson1 at worldnet.att.ne t
Nov 15 '05 #11

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

Similar topics

5
22101
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) {
6
16063
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++)
10
7521
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++)
1
4491
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:
3
16847
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
10
9402
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';
11
12813
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
6
2063
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);
10
4919
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)
0
10095
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9931
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,...
0
11447
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
11009
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...
0
9799
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...
1
8155
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7314
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
6011
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...
0
6215
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.