Skip to Content.
Sympa Menu

freetds - Re: element of style

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: James K. Lowden <jklowden AT speakeasy.org>
  • To: "TDS Development Group" <freetds AT franklin.oit.unc.edu>
  • Subject: Re: element of style
  • Date: Sat, 24 Aug 2002 15:29:15 -0400


On 24 Aug 2002 11:57:02 +0200, "Frediano Ziglio" <freddyz77 AT tin.it> wrote:

> > Best, I'm sure, would be to include <limits.h> and apply some autoconf
> > magic to define things such that this would work:
> >
> > if (num > INT_16_MAX)
> >
>
> INT_16_MAX is quite different from INT_MAX. We don't know INT_MAX in
> every platform but INT_16_MAX is always 0x8000...

I meant 16 *pairs* of bits. ;) No, you caught me half asleep I think. We
need INT_32_MAX there.

> The only problem should be INT_64_MAX... is
> 0x8000000000000000l or
> 0x8000000000000000ll or
> 0x8000000000000000i64 ?
> There are some defines in inttypes.h to handle this stuff...
> Perhaps is better to define because is easy to forgot a zero...

(please use "L" at the end, not "l". Maybe it's my fault for using a
lousy font, but I can hardly tell 1l1l1l1l1l1l1 from l1l1l1l1l1l1l.)

I don't know what 0x8000000000000000i64 is, sorry.

My limits.h defines three useful values:

#define UQUAD_MAX 0xffffffffffffffffULL /* max unsigned
#quad */ define QUAD_MAX 0x7fffffffffffffffLL /* max
#signed quad */ define QUAD_MIN (-0x7fffffffffffffffLL-1) /*
#min signed quad */

One lesson being that tests against maxima have to be "<=", not "<" e.g.,
"i <= QUAD_MAX".

My suggestion for the ultimate in portable boundaries:

1. With autoconf, we can learn the name of 8-, 16-, 32-, and 64-bit
integers.
2 From limits.h, we can acquire the #define'd max/min of each integer
type
3. In tds.h.in, we can map 1,2 to INT_8_MAX etc.
4. In convert.c, we can use our definitions.

It is weird we have to do this at all, weird that there are no standard
terms for integer limits based on the number of bits. If there's no Right
Way to do this, we might wind up with a contribution to gcc?!

limits.h is posix-defined and should be on every machine. If it's not, we
can deal with that the way we deal with every nonstandard noncompiler out
there: with autoconf. If it's got another name or set of definitions, we
can deal with that, or define our own for those cases.

As long as we rely on limits.h, we put ourselves in the hands of the
fellows who provided cc on that machine. Those are good hands. That
makes it a good bet that for instance the minimum signed 64-bit int will
be defined on that box in such as way that it compiles.

--jkl




Archive powered by MHonArc 2.6.24.

Top of Page