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

G

G. Peter

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 ([email protected])
 
V

Victor Bazarov

G. Peter said:
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
 
G

G. Peter

Victor said:
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 ...
 
V

Victor Bazarov

G. Peter said:

Thanks. Doesn't help, unfortunately.
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.
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 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
 
K

Karl Heinz Buchegger

G. Peter said:
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?
 
G

Gregor Peter

Karl said:
:


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.




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

Gregor Peter

Victor said:
Thanks. Doesn't help, unfortunately.




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 ...
 
V

Victor Bazarov

Gregor Peter said:
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
 
J

John Harrison

G. Peter said:

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
 
F

foo

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


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 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.
 
G

G. Peter

John said:
"G. Peter" <[email protected]> wrote in message news:[email protected]...
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?
 
K

Karl Heinz Buchegger

Gregor said:
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


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.
 
D

Dhruv

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

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



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.
 
J

John Harrison

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

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



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
 
J

John Harrison

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
 
G

G. Peter

John said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top