g++ warning

T

TheFlyingDutchman

I have code that compiled without warning in the past on other
compilers
_________________________________________________
static char *full_month_names[] =
{
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
};
________________________________________
but I am getting a warning from g++:
warning: deprecated conversion from string constant to 'char*'

Is there a way to do this without a warning that uses char * or is
this supposed to be one using a string class now?
 
W

Wojciech Waga

W dniu 13.05.2011 09:53, TheFlyingDutchman pisze:
I have code that compiled without warning in the past on other
compilers
_________________________________________________
static char *full_month_names[] =
{
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
};
________________________________________
but I am getting a warning from g++:
warning: deprecated conversion from string constant to 'char*'

Is there a way to do this without a warning that uses char * or is
this supposed to be one using a string class now?

Do wat is says:

static const char *full_month_names...

Conversion from these literals to char* with write access is lame that's
why the warning :)

best
w.
 
M

Marc

TheFlyingDutchman said:
I have code that compiled without warning in the past on other
compilers
_________________________________________________
static char *full_month_names[] =
{
"January",

Did you try sticking a "const" next to "char"?
 
T

TheFlyingDutchman

W dniu 13.05.2011 09:53, TheFlyingDutchman pisze:








I have code that compiled without warning in the past on other
compilers
_________________________________________________
   static char *full_month_names[] =
       {
          "January",
          "February",
          "March",
          "April",
          "May",
          "June",
          "July",
          "August",
          "September",
          "October",
          "November",
          "December"
       };
________________________________________
but I am getting a warning from g++:
warning: deprecated conversion from string constant to 'char*'
Is there a way to do this without a warning that uses char *  or is
this supposed to be one using a string class now?

Do wat is says:

static const char *full_month_names...

Conversion from these literals to char* with write access is lame that's
why the warning :)

best
w.

Thanks.
 
T

TheFlyingDutchman

TheFlyingDutchman  wrote:
I have code that compiled without warning in the past on other
compilers
_________________________________________________
  static char *full_month_names[] =
      {
         "January",

Did you try sticking a "const" next to "char"?

No, I was confused by the term "string constant". I would have if the
message had been:

warning: deprecated conversion from 'const char *' to 'char*'.
 
M

Marc

TheFlyingDutchman said:
TheFlyingDutchman  wrote:
I have code that compiled without warning in the past on other
compilers
_________________________________________________
  static char *full_month_names[] =
      {
         "January",

Did you try sticking a "const" next to "char"?

No, I was confused by the term "string constant". I would have if the
message had been:

warning: deprecated conversion from 'const char *' to 'char*'.

Feel free to file an enhancement request with gcc for a clearer
warning (say one that comes with a hint that char* should possibly be
replaced by either const char* or char[] (that last possibility
doesn't apply here)).
 
A

arnuld

No, I was confused by the term "string constant". I would have if the
message had been:

warning: deprecated conversion from 'const char *' to 'char*'.


Aha.. reminds me of my earliest days of my attempts to learn C++
programming. I had same confusion :) and unlike Marc, I did not get
the idea of mailing gcc guys for enhacement request.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top