confused g++ err msg 'deprecated conversion from string constantto char*'

Discussion in 'C++' started by G. Peter, Jun 26, 2003.

  1. G. Peter

    G. Peter Guest

    Hi there,

    I've a 'funny' error message of my compiler (g++ 2.95.4) that tells me:

    robot.cpp: In method `Robot::Robot()':
    robot.cpp:19: warning: deprecated conversion from string constant to `char *'


    In Line 19 of my file 'robot.cpp' I declare the constructor of class
    robot like:

    18
    19 Robot::Robot(){
    20
    21 cout << "welcome to Robot's ctor!" << endl;
    22
    23 //do some things ...
    24
    25 } // end ctor
    26

    In line 19 are no 'strings' or 'char*s', or am I blind?
    Do I call a deep hidden lib or something without knowing it?


    OK, it is a warning so it seems not to be very seroius.
    That was what I thougt but I was wrong!

    I can compile the prog, but it does not work! :-(

    The mysterious thing is, when I start the debugger I reach line 19 but
    never line 20.



    Thanks for reading this

    Gregor ()
     
    G. Peter, Jun 26, 2003
    #1
    1. Advertising

  2. Re: confused g++ err msg 'deprecated conversion from string constant to char*'

    "G. Peter" <> wrote...
    > I've a 'funny' error message of my compiler (g++ 2.95.4) that tells me:
    >
    > robot.cpp: In method `Robot::Robot()':
    > robot.cpp:19: warning: deprecated conversion from string constant to `char

    *'
    >
    >
    > In Line 19 of my file 'robot.cpp' I declare the constructor of class
    > robot like:
    >
    > 18
    > 19 Robot::Robot(){
    > 20
    > 21 cout << "welcome to Robot's ctor!" << endl;
    > 22
    > 23 //do some things ...
    > 24
    > 25 } // end ctor
    > 26
    >
    > In line 19 are no 'strings' or 'char*s', or am I blind?


    What's the class definition look like?

    > Do I call a deep hidden lib or something without knowing it?


    Compilers often miscalculate the line number. Are you sure it's
    that precise line?

    > OK, it is a warning so it seems not to be very seroius.
    > That was what I thougt but I was wrong!
    >
    > I can compile the prog, but it does not work! :-(


    Unfortunately, nothing can be advised based on the amount of code
    you decided to share.

    > The mysterious thing is, when I start the debugger I reach line 19 but
    > never line 20.


    I don't know what to tell you except, "Upgrade your compiler".

    Victor
     
    Victor Bazarov, Jun 26, 2003
    #2
    1. Advertising

  3. G. Peter

    G. Peter Guest

    Victor Bazarov wrote:

    > What's the class definition look like?

    www.rob.uni-luebeck.de/~peter/Class_Robot/robot.h


    > Compilers often miscalculate the line number. Are you sure it's
    > that precise line?

    How can I?
    But I am not dealing with stings at all (as far as I know :)


    > Unfortunately, nothing can be advised based on the amount of code
    > you decided to share.

    For an answer I give you all the code I have
    See the complete code at

    http://www.rob.uni-luebeck.de/~peter/Class_Robot


    > I don't know what to tell you except, "Upgrade your compiler".

    I tried that, but that has a lot of other side effects which is topic in
    a different news group ...
     
    G. Peter, Jun 26, 2003
    #3
  4. Re: confused g++ err msg 'deprecated conversion from string constant to char*'

    "G. Peter" <> wrote...
    > Victor Bazarov wrote:
    >
    > > What's the class definition look like?

    > www.rob.uni-luebeck.de/~peter/Class_Robot/robot.h


    Thanks. Doesn't help, unfortunately.

    > > Compilers often miscalculate the line number. Are you sure it's
    > > that precise line?

    > How can I?


    You could use some kind of compiler-specific macro to output
    the line number (__LINE__ should expand to that). You could
    put #error after that line and see if it does come to it...

    > But I am not dealing with stings at all (as far as I know :)


    The warning often appears at this:

    char *str = "abc";

    "abc" has type const char[], and 'str' is a char*. Initialisation
    of a pointer to char with a pointer to (or array of) const char is
    allowed but is not advised.

    >
    >
    > > Unfortunately, nothing can be advised based on the amount of code
    > > you decided to share.

    > For an answer I give you all the code I have
    > See the complete code at
    >
    > http://www.rob.uni-luebeck.de/~peter/Class_Robot


    Sorry, this is not the complete code.

    > > I don't know what to tell you except, "Upgrade your compiler".

    > I tried that, but that has a lot of other side effects which is topic in
    > a different news group ...


    Well, it's up to you then.

    Victor
     
    Victor Bazarov, Jun 26, 2003
    #4
  5. Re: confused g++ err msg 'deprecated conversion from string constanttochar*'

    "G. Peter" wrote:
    >
    > Victor Bazarov wrote:
    >
    > > What's the class definition look like?

    > www.rob.uni-luebeck.de/~peter/Class_Robot/robot.h
    >
    > > Compilers often miscalculate the line number. Are you sure it's
    > > that precise line?

    > How can I?


    Well.
    You could comment out the line in question and see if the error goes away.
    Or you could introduce an intentional error before or after the line
    in question and see if the compiler emits the expected line number for
    that error.

    eg.

    > 19 Robot::Robot(){


    ijkl;
    > 20
    > 21 cout << "welcome to Robot's ctor!" << endl;
    > 22
    > 23 //do some things ...


    Now you would expect an error at line 20 saying that identifier ijkl
    is undefined. The question now is: does the compiler say: line 20
    or something else?

    --
    Karl Heinz Buchegger
     
    Karl Heinz Buchegger, Jun 26, 2003
    #5
  6. G. Peter

    Gregor Peter Guest

    Re: confused g++ err msg 'deprecated conversion from string constanttochar*'

    Karl Heinz Buchegger wrote:
    >
    > "G. Peter" wrote:


    >>>Compilers often miscalculate the line number. Are you sure it's
    >>>that precise line?

    >>
    >>How can I?

    >
    >
    > Well.
    > You could comment out the line in question and see if the error goes away.

    Uneately this line is needed, it is the signature of the constructor.
    I tried to rewrite it and reduced it to the absolute minmal without nany
    changings

    > Or you could introduce an intentional error before or after the line
    > in question and see if the compiler emits the expected line number for
    > that error.
    >
    > eg.
    >
    >
    >>19 Robot::Robot(){

    >
    >
    > ijkl;
    >
    >>20
    >>21 cout << "welcome to Robot's ctor!" << endl;
    >>22
    >>23 //do some things ...

    >
    >
    > Now you would expect an error at line 20 saying that identifier ijkl
    > is undefined. The question now is: does the compiler say: line 20
    > or something else?
    >


    I did that and the compiler answerd:
    robot.cpp:20: `ijkl' undeclared (first use this function)

    So that means no miscalculation of the compiler!?!
     
    Gregor Peter, Jun 26, 2003
    #6
  7. G. Peter

    Gregor Peter Guest

    Victor Bazarov wrote:
    > "G. Peter" <> wrote...
    >
    >>Victor Bazarov wrote:
    >>
    >>
    >>>What's the class definition look like?

    >>
    >>www.rob.uni-luebeck.de/~peter/Class_Robot/robot.h

    >
    >
    > Thanks. Doesn't help, unfortunately.
    >



    >>
    >> http://www.rob.uni-luebeck.de/~peter/Class_Robot

    >
    >
    > Sorry, this is not the complete code.

    What else do you need?
    The usesd lib 'GropLight' won't help you cause it will ask for some
    certain hardware (an industrial robot you probably don't have ...)

    I'll introduce the maco USE_GROPE in robot.h, if not defined it will
    leave out all GropeLight specific things so it should be compileable
    without the robot.

    hmm ... I feel this is not done in 5 minutes, give me some time to do
    that I will let you know (by sending a eMail?) if it is done ...
     
    Gregor Peter, Jun 26, 2003
    #7
  8. Re: confused g++ err msg 'deprecated conversion from string constant to char*'

    "Gregor Peter" <-luebeck.de> wrote...
    > Victor Bazarov wrote:
    > > "G. Peter" <> wrote...
    > >
    > >>Victor Bazarov wrote:
    > >>
    > >>
    > >>>What's the class definition look like?
    > >>
    > >>www.rob.uni-luebeck.de/~peter/Class_Robot/robot.h

    > >
    > >
    > > Thanks. Doesn't help, unfortunately.
    > >

    >
    >
    > >>
    > >> http://www.rob.uni-luebeck.de/~peter/Class_Robot

    > >
    > >
    > > Sorry, this is not the complete code.

    > What else do you need?
    > The usesd lib 'GropLight' won't help you cause it will ask for some
    > certain hardware (an industrial robot you probably don't have ...)


    Without it I cannot compile the project.

    > I'll introduce the maco USE_GROPE in robot.h, if not defined it will
    > leave out all GropeLight specific things so it should be compileable
    > without the robot.
    >
    > hmm ... I feel this is not done in 5 minutes, give me some time to do
    > that I will let you know (by sending a eMail?) if it is done ...


    Once you've done that, see if you still get the same error...

    And if you do want to send me the note, pay attention to my
    signature below.

    Good luck!

    Victor
    --
    Please remove capital A's from my address when replying by mail
     
    Victor Bazarov, Jun 26, 2003
    #8
  9. Re: confused g++ err msg 'deprecated conversion from string constant to char*'

    "G. Peter" <> wrote in message news:...
    >
    >
    > Victor Bazarov wrote:
    >
    > > What's the class definition look like?

    > www.rob.uni-luebeck.de/~peter/Class_Robot/robot.h
    >
    >


    Here's a guess.

    CKR6 (which is a base class of Robot) Has a constructor declared something
    like this

    CKR6(char* something = "some_default")

    This would geneate the warning mentioned and you are calling this
    constructor implicitly at the start of your Robot constructor.

    And if this constructor was failing, that would explain why your debug
    session ends when it does.

    john
     
    John Harrison, Jun 26, 2003
    #9
  10. G. Peter

    foo Guest

    Re: confused g++ err msg 'deprecated conversion from string constant to char*'

    "G. Peter" <> wrote in message news:<>...
    > Victor Bazarov wrote:
    >
    > > What's the class definition look like?

    > www.rob.uni-luebeck.de/~peter/Class_Robot/robot.h
    >
    >
    > > Compilers often miscalculate the line number. Are you sure it's
    > > that precise line?

    > How can I?
    > But I am not dealing with stings at all (as far as I know :)
    >
    >
    > > Unfortunately, nothing can be advised based on the amount of code
    > > you decided to share.

    > For an answer I give you all the code I have
    > See the complete code at
    >
    > http://www.rob.uni-luebeck.de/~peter/Class_Robot
    >
    >
    > > I don't know what to tell you except, "Upgrade your compiler".

    > I tried that, but that has a lot of other side effects which is topic in
    > a different news group ...



    I notice this header file has both an include iostream.h and a using
    namespace std.
    #include <iostream.h>
    using namespace std;

    This is a real bad combination. <iostream.h> is not part of the C++
    standard, and on some implementations you'll find bugs with it.
    In most implementations <iostream.h> is an <iostream> version with all
    the declarations in the global namespace.

    If you have another source file that includes your header, and it's
    using <iostream>, you could have a conflict, and the compiler may not
    know which one to choose.

    Unlikely that this has any thing to do with your current problem. But
    you never know.
     
    foo, Jun 26, 2003
    #10
  11. G. Peter

    G. Peter Guest

    John Harrison wrote:
    > "G. Peter" <> wrote in message news:...


    >
    > Here's a guess.
    >
    > CKR6 (which is a base class of Robot) Has a constructor declared something
    > like this
    >
    > CKR6(char* something = "some_default")


    That's it
    I added the headers of the used lib on my website.
    The used ctor is indeed:

    CKR6(char* device = "/dev/ttyS0")


    > This would geneate the warning mentioned and you are calling this
    > constructor implicitly at the start of your Robot constructor.




    > And if this constructor was failing, that would explain why your debug
    > session ends when it does.


    CKR6 is not written by myself, I used it in differrent projects before
    with no occurance of any error (in that class) and I can't remember that
    I ever got that warning before.

    I did not expect (and cannot beleve it now) that the ctor of CKR6 cause
    an error.


    Just inheriting and (implicit) using the CKR6 ctor can't be the error,
    can it?
     
    G. Peter, Jun 27, 2003
    #11
  12. Re: confused g++ err msg 'deprecated conversion from stringconstanttochar*'

    Gregor Peter wrote:
    >
    > Karl Heinz Buchegger wrote:
    > >
    > > "G. Peter" wrote:

    >
    > >>>Compilers often miscalculate the line number. Are you sure it's
    > >>>that precise line?
    > >>
    > >>How can I?

    > >
    > >
    > > Well.
    > > You could comment out the line in question and see if the error goes away.

    > Uneately this line is needed, it is the signature of the constructor.
    > I tried to rewrite it and reduced it to the absolute minmal without nany
    > changings
    >
    > > Or you could introduce an intentional error before or after the line
    > > in question and see if the compiler emits the expected line number for
    > > that error.
    > >
    > > eg.
    > >
    > >
    > >>19 Robot::Robot(){

    > >
    > >
    > > ijkl;
    > >
    > >>20
    > >>21 cout << "welcome to Robot's ctor!" << endl;
    > >>22
    > >>23 //do some things ...

    > >
    > >
    > > Now you would expect an error at line 20 saying that identifier ijkl
    > > is undefined. The question now is: does the compiler say: line 20
    > > or something else?
    > >

    >
    > I did that and the compiler answerd:
    > robot.cpp:20: `ijkl' undeclared (first use this function)
    >
    > So that means no miscalculation of the compiler!?!


    Yes. It means that line 19 is indeed the line containing
    the constructor function signature.
    Thus further means you have to concentrate work on that one.

    --
    Karl Heinz Buchegger
     
    Karl Heinz Buchegger, Jun 27, 2003
    #12
  13. G. Peter

    Dhruv Guest

    Re: confused g++ err msg 'deprecated conversion from string constant to char*'

    On Fri, 27 Jun 2003 11:30:25 +0200, G. Peter wrote:

    >
    >
    > John Harrison wrote:
    >> "G. Peter" <> wrote in message news:...

    >
    >>
    >> Here's a guess.
    >>
    >> CKR6 (which is a base class of Robot) Has a constructor declared something
    >> like this
    >>
    >> CKR6(char* something = "some_default")

    >
    > That's it
    > I added the headers of the used lib on my website.
    > The used ctor is indeed:
    >
    > CKR6(char* device = "/dev/ttyS0")
    >
    >
    >> This would geneate the warning mentioned and you are calling this
    >> constructor implicitly at the start of your Robot constructor.

    >
    >
    >
    >> And if this constructor was failing, that would explain why your debug
    >> session ends when it does.

    >
    > CKR6 is not written by myself, I used it in differrent projects before
    > with no occurance of any error (in that class) and I can't remember that
    > I ever got that warning before.
    >
    > I did not expect (and cannot beleve it now) that the ctor of CKR6 cause
    > an error.
    >
    >
    > Just inheriting and (implicit) using the CKR6 ctor can't be the error,
    > can it?


    Yes, it can, because before the derived classes are initialized, all the
    bases are initialized first. So, the ctro for a derived is something like
    this:

    struct base {
    base () {} };

    struct derived: base {
    derived (): base(base()) { } };

    The ctor for derived expands to something like this:

    derived () { this->base = base (); }

    HTH,
    -Dhruv.
     
    Dhruv, Jun 27, 2003
    #13
  14. Re: confused g++ err msg 'deprecated conversion from string constant to char*'

    "G. Peter" <> wrote in message news:...
    >
    >
    > John Harrison wrote:
    > > "G. Peter" <> wrote in message

    news:...
    >
    > >
    > > Here's a guess.
    > >
    > > CKR6 (which is a base class of Robot) Has a constructor declared

    something
    > > like this
    > >
    > > CKR6(char* something = "some_default")

    >
    > That's it
    > I added the headers of the used lib on my website.
    > The used ctor is indeed:
    >
    > CKR6(char* device = "/dev/ttyS0")
    >
    >
    > > This would geneate the warning mentioned and you are calling this
    > > constructor implicitly at the start of your Robot constructor.

    >
    >
    >
    > > And if this constructor was failing, that would explain why your debug
    > > session ends when it does.

    >
    > CKR6 is not written by myself, I used it in differrent projects before
    > with no occurance of any error (in that class) and I can't remember that
    > I ever got that warning before.
    >
    > I did not expect (and cannot beleve it now) that the ctor of CKR6 cause
    > an error.
    >


    Why not? Almost every piece of code ever written has bugs. I'm not saying
    that it is a bug (it could be that you are using CKR6 inappropriately) but
    its certainly worth investigating. It seems pretty clear from your debugging
    that it is crashing in the CKR6 ctor.

    >
    > Just inheriting and (implicit) using the CKR6 ctor can't be the error,
    > can it?
    >


    I don't know enough about how CKR6 is supposed to be used to answer that.

    john
     
    John Harrison, Jun 27, 2003
    #14
  15. Re: confused g++ err msg 'deprecated conversion from string constant to char*'

    >
    >
    > >>
    > >>Just inheriting and (implicit) using the CKR6 ctor can't be the error,
    > >>can it?

    > >
    > >
    > > Yes, it can, because before the derived classes are initialized, all the
    > > bases are initialized first. So, the ctro for a derived is something

    like
    > > this:
    > >
    > > struct base {
    > > base () {} };
    > >
    > > struct derived: base {
    > > derived (): base(base()) { } };
    > >
    > > The ctor for derived expands to something like this:
    > >
    > > derived () { this->base = base (); }
    > >
    > > HTH,
    > > -Dhruv.
    > >

    >
    > OK that makes sense.
    > But what can I do to avid errors here?
    >
    > Does it suffice to 'pre'initialize the base class?
    >
    > like
    > main(){
    > static base myBase( "ttyS0" );
    > derived myDerived( 2.0 )
    > }
    >
    > I'll try that ...
    >


    I think you've misunderstood Dhruv. There's no need to 'preinitialise' a
    base class. I think Dhruv was just trying to point out that you are
    implicitly calling the base class ctor, something you knew already I think.

    john
     
    John Harrison, Jun 27, 2003
    #15
  16. G. Peter

    G. Peter Guest

    John Harrison wrote:
    >>
    >>>>Just inheriting and (implicit) using the CKR6 ctor can't be the error,
    >>>>can it?
    >>>
    >>>
    >>>Yes, it can, because before the derived classes are initialized, all the
    >>>bases are initialized first. So, the ctro for a derived is something

    >>

    > like
    >
    >>>this:
    >>>
    >>>struct base {
    >>>base () {} };
    >>>
    >>>struct derived: base {
    >>>derived (): base(base()) { } };
    >>>
    >>>The ctor for derived expands to something like this:
    >>>
    >>>derived () { this->base = base (); }
    >>>
    >>>HTH,
    >>>-Dhruv.
    >>>

    >>
    >>OK that makes sense.
    >>But what can I do to avid errors here?
    >>
    >>Does it suffice to 'pre'initialize the base class?
    >>
    >>like
    >> main(){
    >>static base myBase( "ttyS0" );
    >>derived myDerived( 2.0 )
    >> }
    >>
    >>I'll try that ...
    >>

    >
    >
    > I think you've misunderstood Dhruv. There's no need to 'preinitialise' a
    > base class. I think Dhruv was just trying to point out that you are
    > implicitly calling the base class ctor, something you knew already I think.
    >
    > john
    >
    >

    Yes I knew that :) but that does not solve my problem.
     
    G. Peter, Jul 1, 2003
    #16
    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.

Share This Page