[Patches] fix simple 64-bit warnings/errors in signalmodule.c and bufferobject.c

Greg Stein gstein@lyra.org
Tue, 6 Jun 2000 12:38:57 -0700 (PDT)


On Tue, 6 Jun 2000, Trent Mick wrote:
>...
> > If keeping the decl
> > "int" is important, then the warning is thoroughly appropriate!  Casting
> > sizeof's result to int is a bad but expedient wormaround.  Defining a
> > SAFE_DOWNCAST macro (that checks that the downcast doesn't lose info in
> > DEBUG mode, and does the downcast without checking in non-DEBUG mode) is a
> > better (but still sucky) wormaround.  C is simply a pain in the ass here.
> > 
> 
> *Is* there a way to express that the downcast is safe that is not sucky?

I think that Tim means something like the following:

#ifdef DEBUG
#  define SAFE_DOWNCAST(v) ((v) <= INT_MAX ? (int)(v) : abort())
#else
#  define SAFE_DOWNCAST(v) ((int)(v))
#endif

My INT_MAX check probably isn't right, but this might be what he is
getting at. Of course, you would also need other variants for different
downcasts.


IMO, you *really* should not need to downcast all that often. I see it
when I/O occurs (to fit something into a specific size), but type/size
mismatches are usually indicative of design/specification errors.

IMO #2, you should not tell the compiler to ignore certain
warnings/errors (e.g. using pragmas). That is the worst scenario of all.
That hides things even worse than a cast.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/