* string literal conversion problem
@ 2005-01-24 21:15 Jack Marr
2005-01-24 21:44 ` Eljay Love-Jensen
0 siblings, 1 reply; 2+ messages in thread
From: Jack Marr @ 2005-01-24 21:15 UTC (permalink / raw)
To: gcc-help
We are getting an error with g++ 3.3.3 when passing a string literal to
a function expecting a void *. The error is seen here:
% cat strlit-to-void-ptr.c
extern void setValue(void * value);
int main(void)
{
setValue("String 1");
char * s2 = "String 2";
setValue(s2);
return 0;
}
% g++ -c strlit-to-void-ptr.c
strlit-to-void-ptr.c: In function `int main()':
strlit-to-void-ptr.c:6: error: invalid conversion from `const void*' to
`void*'
It seems to me that the conversion of 'const char *' to 'char *'
specified in ISO 14882 4.2 ¶2 should be applied prior to the conversion
of 'char *' to 'void *' spec'd in 4.10. I believe this is what allows
the declaration and use of s2 to compile without error.
Also, we don't get a warning for this practice with any of the other 4
compilers we use, which doesn't prove anything but does provide some
support. Are all of those compilers in fact non-compliant or is this a
g++ bug?
--
Jack Marr (marr@ugs.com)
UGS -- Development Environment Tools
Cypress, CA "Ite Ursi"
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: string literal conversion problem
2005-01-24 21:15 string literal conversion problem Jack Marr
@ 2005-01-24 21:44 ` Eljay Love-Jensen
0 siblings, 0 replies; 2+ messages in thread
From: Eljay Love-Jensen @ 2005-01-24 21:44 UTC (permalink / raw)
To: Jack Marr, gcc-help
Hi Jack,
I reread ISO 14882 4.2 and 4.10. Hmm, not sure.
The VERY VERY VERY compliant and strict Edison Design Group C++ front end
(http://www.edg.com/cpp.html) via Comeau
(http://www.comeaucomputing.com/tryitout/) compiler reject your code.
argument of type "const char *" is incompatible with parameter of type "void *"
I'm thinking that your code is not 100% compliant.
You could use the GCC -fno-const-strings compiler flag to work around the
issue that you ran into to with GCC.
Or you could change...
extern void setValue(void * value);
...to...
extern void setValue(void const* value);
Sincerely,
--Eljay
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-01-24 21:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-24 21:15 string literal conversion problem Jack Marr
2005-01-24 21:44 ` Eljay Love-Jensen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).