g++ warning

Discussion in 'C++' started by TheFlyingDutchman, May 13, 2011.

  1. 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?
     
    TheFlyingDutchman, May 13, 2011
    #1
    1. Advertising

  2. 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.
     
    Wojciech Waga, May 13, 2011
    #2
    1. Advertising

  3. TheFlyingDutchman

    Marc Guest

    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"?
     
    Marc, May 13, 2011
    #3
  4. On May 13, 1:02 am, Wojciech Waga <> wrote:
    > 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.
     
    TheFlyingDutchman, May 13, 2011
    #4
  5. On May 13, 1:04 am, Marc <> wrote:
    > 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*'.
     
    TheFlyingDutchman, May 13, 2011
    #5
  6. TheFlyingDutchman

    Marc Guest

    TheFlyingDutchman wrote:

    > On May 13, 1:04 am, Marc <> wrote:
    >> 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)).
     
    Marc, May 13, 2011
    #6
  7. TheFlyingDutchman

    arnuld Guest

    > On May 13, 2:18 pm, TheFlyingDutchman <> wrote:

    > 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.
     
    arnuld, May 20, 2011
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike Treseler

    Re: Quartus warning in NUMERIC_STD.vhd

    Mike Treseler, Jul 11, 2003, in forum: VHDL
    Replies:
    2
    Views:
    1,861
    Clyde R. Shappee
    Jul 13, 2003
  2. Pete Becker
    Replies:
    0
    Views:
    1,391
    Pete Becker
    Feb 10, 2005
  3. B. Williams

    warning C4267 and warning C4996

    B. Williams, Oct 26, 2006, in forum: C++
    Replies:
    17
    Views:
    2,649
  4. WARNING! Prosoftstore.com is a SCAM! WARNING!

    , Jul 8, 2007, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    337
  5. Julian Mehnle
    Replies:
    17
    Views:
    915
    Julian Mehnle
    May 18, 2006
Loading...

Share This Page