DRAFT document on coding conventions in kde libraries

Thiago Macieira thiago at kde.org
Mon Mar 6 09:44:21 GMT 2006

Allan Sandfeld Jensen wrote:
>On Monday 06 March 2006 08:21, Andras Mantia wrote:
>> On Monday 06 March 2006 01:33, Allan Sandfeld Jensen wrote:
>> > On Sunday 05 March 2006 19:25, Frans Englich wrote:
>> > > * Mention that people should avoid C style casts. Especially in
>> > > headers but also in implementation. From my knowledge: C++ style
>> > > casts are stricter and therefore gives the compiler better options
>> > > for statically detecting errors, and in some cases invalid casts
>> > > are generated by C-style casts.
>> >
>> > I do not agree. I think it is more important to warn against
>> > dynamic_cast<> and recommend qobject_cast<> or static_cast<>/C style
>> > casts instead.
>> What is your problem with dynamic_cast (aside that I read qobject_cast
>> is faster, but only for QObject derivate classes)?
>It is unreliable across shared libaries. If you have a non-QObject based
>heirachy you should implement your own type-system rather than rely on

I'd rather people used dynamic_cast<> rather than write and rewrite their 
own system.

They just have to be warned against the pitfalls that it may represent. In 
special: do not ever use dynamic_cast in a class that is not marked 

People shouldn't use C-style casts, but sometimes they may have to. 
Headers, however, should be clean of them.

  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

1. On frumscafte, hwonne time_t wæs náht, se scieppend þone circolwyrde 
wundorcræftlíge cennede and seo eorðe wæs idel and hit wæs gód.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20060306/c111ca83/attachment.sig>

More information about the kde-core-devel mailing list