Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > g++ warning

Reply
Thread Tools

g++ warning

 
 
TheFlyingDutchman
Guest
Posts: n/a
 
      05-13-2011
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?
 
Reply With Quote
 
 
 
 
Wojciech Waga
Guest
Posts: n/a
 
      05-13-2011
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.
 
Reply With Quote
 
 
 
 
Marc
Guest
Posts: n/a
 
      05-13-2011
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"?
 
Reply With Quote
 
TheFlyingDutchman
Guest
Posts: n/a
 
      05-13-2011
On May 13, 1:02*am, Wojciech Waga <adun_wywal...@o2.pl> 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.
 
Reply With Quote
 
TheFlyingDutchman
Guest
Posts: n/a
 
      05-13-2011
On May 13, 1:04*am, Marc <marc.gli...@gmail.com> 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*'.



 
Reply With Quote
 
Marc
Guest
Posts: n/a
 
      05-13-2011
TheFlyingDutchman wrote:

> On May 13, 1:04*am, Marc <marc.gli...@gmail.com> 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)).
 
Reply With Quote
 
arnuld
Guest
Posts: n/a
 
      05-20-2011
> On May 13, 2:18*pm, TheFlyingDutchman <zzbba...@aol.com> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
WARNING! Prosoftstore.com is a SCAM! WARNING! pentologer@gmail.com ASP .Net Web Services 0 07-08-2007 10:03 AM
warning C4267 and warning C4996 B. Williams C++ 17 10-27-2006 09:41 PM
Untraceable warning: "Warning: Use of "require" without parenthesesis ambiguous at (eval 23) line 1." Julian Mehnle Perl Misc 17 05-18-2006 11:00 AM
Warning: WARNING Charles Computer Support 7 08-16-2005 09:07 PM
Re: A code fix for MSVC warning C4267 (64-bit compatibility warning,e.g. Boost Spirit) Pete Becker C++ 0 02-10-2005 01:13 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57