GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 10-Mar-2010, 20:56
Petr_Kropotkin Petr_Kropotkin is offline
Junior Member
 
Join Date: Feb 2010
Posts: 77
Petr_Kropotkin is on a distinguished road

Depreciated conversion


how do i get rid of these notices ?
main.cpp:24: warning: deprecated conversion from string constant to 'char*'
Here is a sample array
CPP / C++ / C Code:

static char *upto20[]={"one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty"};


I got a bunch of em in my code, and these gcc bothers me with 'em.
  #2  
Old 10-Mar-2010, 23:12
Zenith@BIET Zenith@BIET is offline
New Member
 
Join Date: Mar 2010
Posts: 1
Zenith@BIET is on a distinguished road
Wink

Re: depreciated conversion


Multiple solutions to your problem

1) use gcc flag to supress the warning
-Wno-write-strings
2) make upto20 pointers as "static const" instead of static

3) Al though if you want to modiy the the values better to use two dimmensional array instead of array of pointers
  #3  
Old 20-Mar-2010, 11:07
Petr_Kropotkin Petr_Kropotkin is offline
Junior Member
 
Join Date: Feb 2010
Posts: 77
Petr_Kropotkin is on a distinguished road

Re: Depreciated conversion


I tried it out and I still get errors.
By the way I am using QT Creator with gcc.
  #4  
Old 20-Mar-2010, 13:03
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,496
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Depreciated conversion


Quote:
Originally Posted by Petr_Kropotkin
By the way I am using QT Creator with gcc.
Why not just compile from a command line? There is no way (no way) that helpers can know what the project settings (command-line switches, etc) are in effect when you use QT Creator as the basis for your compilation. There is (almost) no way for helpers to help, beyond what has already been suggested, if we don't see some more code and the exact error messages, including line numbers, etc.

Quote:
Originally Posted by Petr_Kropotkin
...I still get errors...

So: I suggest that you reduce your program to the smallest amount of stuff that exhibits the problematic behavior and post the entire program. Show the command line that was used to compile the code. If you get compiler messages (or any other problems) that you don't understand and can't resolve, then paste the exact messages into your post.

Bottom line: Don't just tell us; show us. If there are lots and lots of messages that are essentially the same, then just post the first ten or so.

In the meanwhile: maybe you can try something like the following:
CPP / C++ / C Code:
#include <iostream>
#include <iomanip>

using namespace std;

const char *int_to_word(int i);

int main()
{
    cout << "Test of int_to_word()" << endl << endl;
     cout << "  i : Returned value" << endl;
    cout << "----------------------" << endl;
    for (int i = -2; i < 23; i++) {
        cout << setw(3) <<  i << " : <" << int_to_word(i) << ">" << endl;
    }
    return 0;
}

const char *int_to_word(int i)
{
    static const char *upto20[22] = {
        "zero",
        "one"    , "two"      , "three"   , "four"    , "five"   ,
        "six"    , "seven"    , "eight"   , "nine"    , "ten"    ,
        "eleven" , "twelve"   , "thirteen", "fourteen", "fifteen",
        "sixteen", "seventeen", "eighteen", "nineteen", "twenty" ,
        "Out of Bounds"
    };
    if ((i < 0) || (i > 20)) {
        return upto20[21];
    }
    else {
        return upto20[i];
    }
}


Compiled with
Code:
g++ -Wwrite-strings -W -Wall -Wextra -pedantic -Werror test_int_to_word.cpp -o test_int_to_word

No compiler messages (warnings or otherwise) with g++ version 4.1.2


Output:
Code:
Test of int_to_word() i : Returned value ---------------------- -2 : <Out of Bounds> -1 : <Out of Bounds> 0 : <zero> 1 : <one> 2 : <two> 3 : <three> 4 : <four> 5 : <five> 6 : <six> 7 : <seven> 8 : <eight> 9 : <nine> 10 : <ten> 11 : <eleven> 12 : <twelve> 13 : <thirteen> 14 : <fourteen> 15 : <fifteen> 16 : <sixteen> 17 : <seventeen> 18 : <eighteen> 19 : <nineteen> 20 : <twenty> 21 : <Out of Bounds> 22 : <Out of Bounds>


Regards,

Dave
Last edited by davekw7x : 20-Mar-2010 at 14:11.
 
 

Recent GIDBlogVista ?Widgets? on Windows XP by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem executing nam-1.13 RodolfoAlvizu Computer Software Forum - Linux 20 28-Feb-2009 15:23
Linked Lists advice request promsan C Programming Language 74 23-May-2007 08:29
conversion member function question amad1337 C++ Forum 1 13-Jun-2006 20:21
conversion double to float donaldk C Programming Language 5 12-Feb-2006 23:16
C Currency Conversion program help needed mutt C Programming Language 1 13-Jun-2004 15:14

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:01.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.