Problems with "error: invalid conversion from `const char*' to `char*' "
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Problems with "error: invalid conversion from `const char*' to `char*' "
Hi, I need some help. I tried to install obs-ns. It´s based on ns2, but when I ran "make", the problem below appears... please I wish anybody would help me.
This is the error:
Code:
OBS/ns-2/integrated_agent.h: In constructor `BurstManager::BurstManager()':
OBS/ns-2/integrated_agent.h:86: warning: `BurstManager::bt_' will be initialized after
OBS/ns-2/integrated_agent.h:84: warning: `int BurstManager::currburstsize_'
OBS/ns-2/integrated_agent.cc:66: warning: when initialized here
OBS/ns-2/integrated_agent.cc: In member function `int BurstManager::nhops(nsaddr_t, nsaddr_t)':
OBS/ns-2/integrated_agent.cc:81: error: invalid conversion from `const char*' to `char*' <------- this is the error
OBS/ns-2/integrated_agent.cc: In member function `virtual void IPKTAgent::recv(Packet*, Handler*)':
OBS/ns-2/integrated_agent.cc:180: warning: unused variable 'ipkth'
/root/OBS/ns-allinone-2.31/tclcl-1.19/tclcl.h:150: error: `void Tcl::error(const char*)' is private
OBS/ns-2/integrated_agent.cc:185: error: within this context
OBS/ns-2/integrated_agent.cc:155: warning: unused variable 'hdr'
OBS/ns-2/integrated_agent.cc: In member function `void IPKTAgent::deBurst(Packet*)':
OBS/ns-2/integrated_agent.cc:192: warning: unused variable 'hdrip'
OBS/ns-2/integrated_agent.cc:194: warning: unused variable 'ch'
make: *** [OBS/ns-2/integrated_agent.o] Error 1
And this is the code of the program...
Code:
int BurstManager::nhops(nsaddr_t src,nsaddr_t des) {
Tcl& tcl = Tcl::instance();
sprintf(tcl.buffer(),"$ns nhops %d %d",src,des);
tcl.eval();
char *ni = tcl.result(); <------this is the line 81
return atoi(ni);
}
Look for the declaration (it should be char *ni; or a similar thing at the top of the function or file. If it has some global significance it might be defined in the matching .h file instead of the .c file. The cause of the problem might lie in that declaration.
Hi, I need some help. I tried to install obs-ns. It´s based on ns2, but when I ran "make", the problem below appears... please I wish anybody would help me.
Maybe this means some older compiler didn't mind that the code was wrong. (The alternative theory would be a bigger problem: obs-ns might be based on some earlier, possibly incompatible, version of the Tcl header files).
But that error looks easy enough to correct, so try correcting it. That might just move down to the next error. But it's worth a try.
Quote:
Code:
int BurstManager::nhops(nsaddr_t src,nsaddr_t des) {
Tcl& tcl = Tcl::instance();
sprintf(tcl.buffer(),"$ns nhops %d %d",src,des);
tcl.eval();
char *ni = tcl.result(); <------this is the line 81
return atoi(ni);
}
This is NOT a generic fix for other places you get that same error message. It works here only because of the way ni is used before it goes out of scope.
I greatly prefer
char const* ni = tcl.result();
rather than
const char *ni = tcl.result();
but they mean the same thing and the latter should be more obvious to a C++ beginner from the original code plus the error message.
You might also want to check and see if there is a newer version of the package, or if a fix for your problem already exists. It is very rare that you're the only one to ever see a problem like that. Just my 2c.
Rather than try and debug the code, I would just check the documentation and verify the software requirements and make sure your versions all match up.
Rather than try and debug the code, I would just check the documentation and verify the software requirements and make sure your versions all match up.
Thanks guys
I use Fedora Core 3 and this software (obs-ns) was developed in 2000 or 2001. I didn't find a new version. I try to install in Fedora 9 and in Ubuntu 7.1 but it doesn´t work. Additionally, I use ns-allinone-2.31 with the most recently packages of all. I try this:
change g++ version, probably to an older one, check the docs
look for patches that allow it to compile under newer compilers
This is a relatively frequent problem because of bad programming practices sometimes. Each version of the compiler is, in general, stricter than the previous one in which regards the acknowledgment of the standads.
I resolved some problems but I have another problem:
Code:
OBS/ns-2/stats.cc: In member function `virtual int StatCollector::command(int, const char* const*)':
OBS/ns-2/stats.cc:59: warning: unused variable 'tcl'
OBS/ns-2/stats.cc: In member function `void StatCollector::dumpstats(const char*, float, float, int)':
OBS/ns-2/stats.cc:81: error: `ofstream' undeclared (first use this function) <------------this error
OBS/ns-2/stats.cc:81: error: (Each undeclared identifier is reported only once for each function it appears in.)
OBS/ns-2/stats.cc:81: error: expected `;' before "outfile1"
OBS/ns-2/stats.cc:82: error: expected `;' before "outfile2"
OBS/ns-2/stats.cc:84: error: `outfile1' undeclared (first use this function)
OBS/ns-2/stats.cc:84: error: `outfile2' undeclared (first use this function)
OBS/ns-2/stats.cc:85: error: `cerr' undeclared (first use this function)
OBS/ns-2/stats.cc:85: error: `endl' undeclared (first use this function)
make: *** [OBS/ns-2/stats.o] Error 1
I don't think you mentioned which version of gcc you're using.
One detail became way pickier, (I think in version 4.3): You need the correct #include directives.
In earlier versions, some include files brought in other definitions they weren't supposed to, so things like your example ofstream might be defined even thought the right #include isn't present.
So you just need to add the right #include near the top of the .cc file. But I never learned how you're supposed to look up which is the right #include for a specific function. (Any experts here what to tell me that one?)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.