lkml.org 
[lkml]   [1996]   [Nov]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: Reverse the ucdrom.h patch in 2.1.12
Date

Linus Torvalds wrote:
>

[snip]

> Hmm.. Personally, I consider pointer casts a bug by default, which was why
> I applied the non-cast version instead.
>
> If pointer casts are needed, I'd much prefer them done through another
> interface, one such being for example:
>
> initialize_cdrom(capacity,speed);
>
> with initialize_cdrom() being a inline function or whatever that then does
> the casting.
>
> The _reason_ I consider pointer casts a bug is that they mess with the C
> type checking. "What type checking?" I hear you say.. But in fact C type
> checking is very practical if done correctly, and one reason I use "-Wall"
> with gcc for everything I write. If the stuff is ever changed (to use
> "long" for example), the code that uses casts will never result in a
> compiler warning, yet it will be hopelessly incorrect unless fixed.
>
> Now, a inline function that does the same cast results in the same _code_,
> but then the cast is hidden in one place (and if the inline function is
> placed near enough the definition of the types, anybody who changes the
> type is likely to change the inline function to mess with the type as
> well).
>
> If you think I'm looking for something like objects but without the
> overhead of a object-oriented language, you're getting pretty close.
>
> Thought of the day: "Any interface that _requires_ the programmer to use
> a cast is a bad interface".
>
> Anybody want to send me patches?
>
> Linus
>

OK for me, but just one example of a good usage of pointer casting.
Accessing a peripheral that may return value on 8 or 16 bits in its
DMA buffer, such as a soundcard with DMA mmaping, is really beautiful.
Depending on the resolution that you want, you cast the mmaped area
form (void *) to (short *) or (char *). Yeap, this is still very marginal..

--
Philippe Strauss, CH-1092 Belmont

Email: <philippe.strauss@urbanet.ch>
Homepage: http://sicel-home-1-4.urbanet.ch

\
 
 \ /
  Last update: 2005-03-22 13:38    [W:0.036 / U:0.120 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site