This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: ... discard qualifiers ...
> is there a way other than '-fwritable-strings' to avoid errors
> in this case :
> typedef void * Pointer;
>
> void foo(const Pointer p)
> {
> ...
> }
>
> void main()
> {
> foo( "Hello World !" );
> }
Well, this *is* an error, in C++, and g++ only accepts it as an
extension. There is a number of ways to correct this error:
typedef void * Pointer;
void foo(const Pointer p)
{
}
int main()
{
foo( (Pointer)("Hello World !") );
}
Note that this has undefined behaviour if the object behind foo::p is
modified. To correct this also, you can do
typedef void * Pointer;
void foo(const Pointer p)
{
}
int main()
{
char hw[] = "Hello World !";
foo(hw);
}
If you need further information why your code is incorrect, or why
these changes fix the problem, please post them in
comp.lang.c++.moderated.
Regards,
Martin