[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: getting char data out of QStrings in Qt 2.0
From:       Stephan Kulow <coolo () itm ! mu-luebeck ! de>
Date:       1999-04-30 11:53:10
[Download RAW message or body]

> 
> On Sat, May 01, 1999 at 12:23:21AM +0000, Mosfet wrote:
> > I actually kind of like the cast but looking at other people's work I seem to
> > be the only one ;-)
> > 
> > I'll change my stuff accordingly.
> > 
> 
> I like the cast too, because it allows to change the variable to a char *
> without changing the method calls. And when using an API (kdelibs), you
> don't have to worry about whether the member is a char * or a QString -
> take KURL, for example, all char * are QStrings now, so the cast (ofter
> implicit) is used very often.
> 
And you'll cast const away just happily without having a way to find out
that this violates some rules the interface predicts. But my favorite
argument is, that you can better find out the meaning of the code using
scripts or parsing tools if you declare what you mean in writing the code.
So if you want to use the ascii representation, use ::ascii(). If you want
to have the QString represented as array of chars, use (const char*). But
who tells you, that (const char*) does the right thing and will continue
to do so? It could also do "return (const char*)(this);" and you would have
no way to check if your code is still correct. But if ascii() stops doing
what you want, you can just s/ascii/whatever

That's important! Please use casts only where you know for sure what you
do and that it will be the right thing. For example I consider casting
enums to ints a bearable thing if you declard the enums as OR-masks.

Greetings, Stephan

-- 
Stephan Kulow (coolo@kde.org)
detrever lleps ot ysae ylgnizama s'ti

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic