Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > cannot convert parameter 2 from 'const char *' to 'char *'

Reply
Thread Tools

cannot convert parameter 2 from 'const char *' to 'char *'

 
 
Alfonso Morra
Guest
Posts: n/a
 
      08-12-2005
Hi,

I'm using a third party library which has a function that expects an arg
of type const char*. I have a char* which is assigned a value at run
time - how can I pass it to my function?

Thanks

 
Reply With Quote
 
 
 
 
Krishanu Debnath
Guest
Posts: n/a
 
      08-12-2005

Alfonso Morra wrote:
> Hi,
>
> I'm using a third party library which has a function that expects an arg
> of type const char*. I have a char* which is assigned a value at run
> time - how can I pass it to my function?
>
> Thanks


Probably you told us the opposite. Your function expects a char*
argument and you
are passing const char* actual. Use a explicit char* cast before
passing it to the function, thats the only option you have.(Assuming
you cannot change third party library function)

--
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
 
 
 
Suman
Guest
Posts: n/a
 
      08-12-2005

Krishanu Debnath wrote:
> Alfonso Morra wrote:
> > Hi,
> >
> > I'm using a third party library which has a function that expects an arg
> > of type const char*. I have a char* which is assigned a value at run
> > time - how can I pass it to my function?
> >
> > Thanks

>
> Probably you told us the opposite. Your function expects a char*
> argument and you
> are passing const char* actual. Use a explicit char* cast before
> passing it to the function, thats the only option you have.(Assuming
> you cannot change third party library function)
>
> --
> (E-Mail Removed)


Any decently written library should have things like when to
use const and when not to, sorted out.
What if the third party modifies the input?
Think of ...
strcpy("Hello", "World");
and you'll get my point.
Better still, copy it to some temporary buffer and pass the buffer.
Surely, some code would have been most welcome here.

 
Reply With Quote
 
Christopher Benson-Manica
Guest
Posts: n/a
 
      08-12-2005
Krishanu Debnath <(E-Mail Removed)> wrote:

> Probably you told us the opposite. Your function expects a char*
> argument and you
> are passing const char* actual. Use a explicit char* cast before
> passing it to the function, thats the only option you have.(Assuming
> you cannot change third party library function)


That's only advisable if the const char * actually points to
modifiable memory; if it does, it might be better off not being
declared const. If it does not (for example, if it points to a string
literal), and the third party function attempts to modify the string
it is passed, tragedy is the likely result.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
(const char *cp) and (char *p) are consistent type, (const char **cpp) and (char **pp) are not consistent lovecreatesbeauty C Programming 1 05-09-2006 08:01 AM
/usr/bin/ld: ../../dist/lib/libjsdombase_s.a(BlockGrouper.o)(.text+0x98): unresolvable relocation against symbol `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostre silverburgh.meryl@gmail.com C++ 3 03-09-2006 12:14 AM
error C2664: 'strcpy' : cannot convert parameter 2 from 'char' to 'const char *' kaizen C++ 3 01-21-2006 08:07 PM
'atoi' : cannot convert parameter 1 from 'char' to 'const char *' John Smith C++ 6 10-31-2005 07:18 AM
cannot convert char** to const char** Brad Moore C++ 5 10-13-2004 06:51 PM



Advertisments