470,632 Members | 1,889 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,632 developers. It's quick & easy.

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

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 (gp**@gmx.de)

Jul 19 '05 #1
15 7194
"G. Peter" <gp**@gmx.de> 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
Jul 19 '05 #2


Victor Bazarov wrote:
What's the class definition look like? http://www.rob.uni-luebeck.de/~peter..._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 ...
Jul 19 '05 #3
"G. Peter" <gp**@gmx.de> wrote...
Victor Bazarov wrote:
What's the class definition look like? http://www.rob.uni-luebeck.de/~peter..._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
Jul 19 '05 #4


"G. Peter" wrote:

Victor Bazarov wrote:
What's the class definition look like? http://www.rob.uni-luebeck.de/~peter..._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
kb******@gascad.at
Jul 19 '05 #5


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!?!


Jul 19 '05 #6


Victor Bazarov wrote:
"G. Peter" <gp**@gmx.de> wrote...
Victor Bazarov wrote:

What's the class definition look like?


http://www.rob.uni-luebeck.de/~peter..._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 ...

Jul 19 '05 #7
"Gregor Peter" <pe***@rob.uni-luebeck.de> wrote...
Victor Bazarov wrote:
"G. Peter" <gp**@gmx.de> wrote...
Victor Bazarov wrote:
What's the class definition look like?

http://www.rob.uni-luebeck.de/~peter..._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
Jul 19 '05 #8

"G. Peter" <gp**@gmx.de> wrote in message news:3E**************@gmx.de...


Victor Bazarov wrote:
What's the class definition look like?

http://www.rob.uni-luebeck.de/~peter..._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
Jul 19 '05 #9
foo
"G. Peter" <gp**@gmx.de> wrote in message news:<3E**************@gmx.de>...
Victor Bazarov wrote:
What's the class definition look like?

http://www.rob.uni-luebeck.de/~peter..._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.
Jul 19 '05 #10


John Harrison wrote:
"G. Peter" <gp**@gmx.de> wrote in message news:3E**************@gmx.de...
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?

Jul 19 '05 #11


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
kb******@gascad.at
Jul 19 '05 #12
On Fri, 27 Jun 2003 11:30:25 +0200, G. Peter wrote:


John Harrison wrote:
"G. Peter" <gp**@gmx.de> wrote in message news:3E**************@gmx.de...


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.






Jul 19 '05 #13

"G. Peter" <gp**@gmx.de> wrote in message news:3E**************@gmx.de...


John Harrison wrote:
"G. Peter" <gp**@gmx.de> wrote in message news:3E**************@gmx.de...

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
Jul 19 '05 #14
>

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
Jul 19 '05 #15


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.

Jul 19 '05 #16

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by frs | last post: by
4 posts views Thread by djake | last post: by
33 posts views Thread by Lalatendu Das | last post: by
10 posts views Thread by Brennan Young | last post: by
15 posts views Thread by rEvolution27 | last post: by
8 posts views Thread by Nikola | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.