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

> On Fri, 22 Nov 1996, Erik B. Andersen wrote:
> >
> > In patch-2.1.12, linux/include/linux/ucdrom.h was changed based on the
> > posting of Gerd Knorr to linux-kernel. I subsequently pointed out that
> > this is the WrongWay(tm) to fix the problem, as this very issue was
> > discussed some time ago in private email. The values for speed and
> > capacity SHOULD be declared const, as these values should not be messed
> > with by anything. However, since these values must be set on drive
> > initialization, and the method utilized in ide-cd to avoid the compilation
> > warnings works just fine.
>
> 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.
Ah, so you want:

typedef int cdrom_capacity_t;
typedef int cdrom_speed_t;
...
struct {
const cdrom_speed_t speed;
const cdrom_capacity_t capacity;
...}
...
*((cdrom_speed_t*)&foo.speed) = speedval; /* discard const on foo.spd */
*((cdrom_capacity_t*)&foo.capacity) = capacityval; /* discard const...*/
...

The one thing I can never remember about C/C++ is which side of the type
name means what for const; then again I've never heard it stated in a way
that makes sense, and I think it's irrelevant unless pointers or references
are involved anyway. Other than that, the above pseudocode is what you
"want" to do, and if it makes your code look a little too Wirth-ish, bury
the typedefs and constructor somewhere that people who need them will find
on the first grep.

Keith (just don't require BLOCK CAPITALS FOR ALL KEYWORDS.)

Disclaimer: Do not taunt Happy Fun God.

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