compilation problem
W. Tasin
tasin at fhm.edu
Thu May 3 12:33:09 BST 2001
Hi,
my 2 euros:
char *s: means you can change the value of s and the content where s
points to.
const char *s: means you can change s but not the values where s points
to, reading it like (const char) *s ... so a pointer s, which refers to
a const char object. So the statement "s++" is allowed.
char const *s: you can change the content where s points to, but not the
value of the the pointer (that's why you don't see this much).
Now what you are trying to do is to assign a pointer txt to a pointer s,
so the content, where txt points to would be accessible by the trick
using s;
Formerly the c++ - compilers gave you only a warning, now its cleaner (I
mean now you have to declare explicitly the this pointer s doesn't point
to "const chars" anymore.)
But I guess you don't want to change the contents of txt.
So why don't you do the following?
void test(const char *txt)
{
const char *s;
s=txt;
while (strlen(s)>0)
{
....
s++;
}
}
This means you are assigning the value of txt, which points to
non-modifyable chars to another pointer which also cannot modify chars.
So you are on the clean side.
Of course you can only pass this pointer to functions which accept
"const char *", like
strlen(const char *s)
Ciao
Walter
Eric KLUMPP wrote:
> Hello,
>
> I am new on this list. I am french and I develop with kdevelop since 3 years.
>
> I just have installed the Mandrake 8.0 that install kdevelop 1.4.1, and now I have the compilation error :
> "cannot convert "const char *" to "char *" in assignment"
> What I do is something like this :
> < void test(const char *txt)
> {
> char *s;
>
> s=txt;
> while (strlen(s)>0)
> {
> ....
> s++;
> }
> }
>
>
> I had the same problem when I tried the Redhat 7.0 but not with the Mandrake 7.2. I think the problem comes from the version of gcc (2.96), but before trying to change to an older version, I prefer to have the confirmation.
>
> If someone has a solution....
> Thanks
>
> Eric
>
>
> -
> to unsubscribe from this list send an email to kdevelop-request at kdevelop.org with the following body:
> unsubscribe »your-email-address«
--
--
oohhh sveglia.... il mondo e' ammalato, ma x colpa di chi.........
(Zucchero)
:-------W. Tasin, FB 04,
FHM-------------------PGP-KeyID:0x7961A645----------:
<Key-Fingerprint: 1610 835F 0080 32F4 6140 6CF7 A7D0 44CD 7961A645>
<http://wwwkeys.pgp.net:11371/pks/lookup?op=index&search=0x7961A645&fingerprint=on>
-
to unsubscribe from this list send an email to kdevelop-request at kdevelop.org with the following body:
unsubscribe »your-email-address«
More information about the KDevelop
mailing list