Mailinglist Archive: opensuse-packaging (183 mails)

< Previous Next >
Re: [opensuse-packaging] error: invalid conversion from 'const char*' to 'char*'
  • From: Martin Vidner <mvidner@xxxxxxx>
  • Date: Mon, 1 Jun 2009 12:24:06 +0200
  • Message-id: <20090601102406.GC23538@xxxxxxxxxxxxxxxx>
On Mon, Jun 01, 2009 at 10:53:13AM +0200, Raymond Wooninck wrote:
On Monday 01 June 2009 07:40:56 Martin Vidner wrote:
we have
char *strchr(char *, int)
const char *strchr(const char *, int)

I am not that well familiar with C++ and maybe an example would work better :

If I have the following statement

char *pp = strchr(str, ';');

(str is a const char), then this one fails with the above error. But would
the
following statement be the right correction :

const char *pp = strchr(str, ';');

That is right.

Except for the case when you then modify the string through pp. (The
compiler would give you another error)
I actually had a case where I put a NUL byte at pp and then the
original character back, so I used
char *pp = (char *) strchr(str, ';');
See here for the actual code:

http://svn.opensuse.org/viewvc/yast/trunk/core/libycp/src/StaticDeclaration.cc?annotate=57367&pathrev=57367#l276
--
Martin Vidner, YaST developer
http://en.opensuse.org/User:Mvidner

Kuracke oddeleni v restauraci je jako fekalni oddeleni v bazenu
--
To unsubscribe, e-mail: opensuse-packaging+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse-packaging+help@xxxxxxxxxxxx

< Previous Next >
List Navigation