g++: warning on deprecated conversion from string constant to ‘char*’

R

Rui Maciel

While recompiling some code with g++ I've stumbled on the following warning:

<warning>
warning: deprecated conversion from string constant to ‘char*’
</warning>

The line in question points to a function that takes a parameter of type
char *, which is being called with a string literal being passed as a
parameter.

After a quick google, the suggested fix which pops out the most consists of
a convoluted cast, which doesn't look right to me.

So, does anyone happens to know how to fix this warning?


Thanks in advance,
Rui Maciel
 
R

Rui Maciel

Rui said:
While recompiling some code with g++ I've stumbled on the following
warning:

<warning>
warning: deprecated conversion from string constant to ‘char*’
</warning>

The line in question points to a function that takes a parameter of type
char *, which is being called with a string literal being passed as a
parameter.


The warning is killed by redefining the function so that it takes a
parameter of type const char *.


Rui Maciel
 
R

Rui Maciel

Rui said:
While recompiling some code with g++ I've stumbled on the following
warning:

<warning>
warning: deprecated conversion from string constant to ‘char*’
</warning>

After a quick google, I've noticed this issue was already covered before in
this newsgroup.

deprecated conversion from string constant to 'char*'
http://groups.google.com/group/comp.lang.c++/browse_frm/thread/f8296092aa73
3645/61bdef5b05e0b511?lnk=gst&q=warning%3A+deprecated+conversion+from+strin
g+constant+to+%E2%80%98char*%E2%80%99#61bdef5b05e0b511


Rui Maciel
 
I

Ian Collins

The warning is killed by redefining the function so that it takes a
parameter of type const char *.

At least one compiler I regularly use has been issuing that warning
since 1998!

Pass the correct type.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top