LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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

Reply
 
LinkBack Search this Thread
Old 11-17-2008, 02:39 PM   #1
dave.f.one
LQ Newbie
 
Registered: Nov 2008
Location: Quito - Ecuador
Distribution: Fedora
Posts: 4

Rep: Reputation: 0
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);
}
 
Old 11-17-2008, 02:45 PM   #2
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,029

Rep: Reputation: 368Reputation: 368Reputation: 368Reputation: 368
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.
 
Old 11-17-2008, 05:25 PM   #3
johnsfine
Senior Member
 
Registered: Dec 2007
Distribution: Centos
Posts: 4,962

Rep: Reputation: 1073Reputation: 1073Reputation: 1073Reputation: 1073Reputation: 1073Reputation: 1073Reputation: 1073Reputation: 1073
Quote:
Originally Posted by dave.f.one View Post
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);
}
just add "const" where required:

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();
  const char *ni = tcl.result();
  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.

Last edited by johnsfine; 11-17-2008 at 05:45 PM.
 
Old 11-17-2008, 06:13 PM   #4
EmrldDrgn
Member
 
Registered: Oct 2008
Posts: 40

Rep: Reputation: 16
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.

Last edited by EmrldDrgn; 11-17-2008 at 06:15 PM.
 
Old 11-17-2008, 09:14 PM   #5
maschiltz
LQ Newbie
 
Registered: Nov 2008
Posts: 6

Rep: Reputation: 0
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.

Good Luck
Mark Schiltz
 
Old 11-17-2008, 09:16 PM   #6
maschiltz
LQ Newbie
 
Registered: Nov 2008
Posts: 6

Rep: Reputation: 0
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.

Good Luck
Mark Schiltz
 
Old 11-17-2008, 11:06 PM   #7
dave.f.one
LQ Newbie
 
Registered: Nov 2008
Location: Quito - Ecuador
Distribution: Fedora
Posts: 4

Original Poster
Rep: Reputation: 0
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:

char const *ni = tcl.result();

And this work, but I have more similar problems.

Thanks for all, but I have more problems.
 
Old 11-18-2008, 02:09 AM   #8
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,029

Rep: Reputation: 368Reputation: 368Reputation: 368Reputation: 368
Then yoy either need to
  • fix all
  • 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.
 
Old 11-18-2008, 10:47 AM   #9
dave.f.one
LQ Newbie
 
Registered: Nov 2008
Location: Quito - Ecuador
Distribution: Fedora
Posts: 4

Original Poster
Rep: Reputation: 0
Another problem with obs-ns

Hi again,

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
 
Old 11-18-2008, 02:40 PM   #10
johnsfine
Senior Member
 
Registered: Dec 2007
Distribution: Centos
Posts: 4,962

Rep: Reputation: 1073Reputation: 1073Reputation: 1073Reputation: 1073Reputation: 1073Reputation: 1073Reputation: 1073Reputation: 1073
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?)

My guess is the line you need to add is

#include <fstream>
 
Old 11-19-2008, 10:01 AM   #11
dave.f.one
LQ Newbie
 
Registered: Nov 2008
Location: Quito - Ecuador
Distribution: Fedora
Posts: 4

Original Poster
Rep: Reputation: 0
I tried with

#include <fstream>

But it doesn´t work

The version of gcc is 3.4.2

this is the code:

Code:
void StatCollector::dumpstats(const char *filename,const float parameter, float simtime,int nagents) {
  char f1name[30],f2name[30]; // one collects stats, one values for the graph

  strcpy(f1name,filename);
  strcpy(f2name,filename);

  strcat(f1name,".stat");
  strcat(f2name,".plot");
  
  ofstream outfile1(f1name,ios ::app);   <------------ this error
  ofstream outfile2(f2name,ios::app);

Last edited by dave.f.one; 11-20-2008 at 09:07 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
invalid conversion from `char' to `const ch predatorz Programming 3 11-15-2008 01:00 PM
about C++ invalid conversion from 'const char*' to 'char' teoporta Programming 3 07-17-2007 09:24 AM
invalid conversion from `const char*' to `char*' deepinlife Programming 22 08-05-2006 10:49 AM
If I get invalid conversion from `const char*' to `char' what should I be lookin for? RHLinuxGUY Programming 5 03-12-2006 10:35 PM
invalid conversion from `char' to `const char* bru Programming 6 05-09-2004 03:07 PM


All times are GMT -5. The time now is 08:51 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration