[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Groff] Using C with glib instead of C++ for groff

From: Antoine Leca
Subject: Re: [Groff] Using C with glib instead of C++ for groff
Date: Fri, 29 Nov 2002 20:27:41 +0100
User-agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.0.0) Gecko/20020530

Werner LEMBERG wrote:
>>For example, the file groff-current/src/libs/libdriver/ has
>>some problems with the integer length of some variables.  Although 32
>>bits are necessary for some constructs, the file only uses `int' as
>>type.  `int' is on GNU PC's wide enough with 32 bits, and `long' is
>>too large with 64 bits.

Yes, this is a common "mistake" that stands within many programs,
from GNU or similar cases. Note that it works quite well, which is
the basic reason why this is used.

 >>But in ANSI C, `int' has 16 bits and `long' has 32 bits.

Strictly speaking (which is what Werner answered), this is not true.
ANSI C says ìnt' should be *at*least* 16-bit, etc. As a result, you
can have a machine where all of short, int and long (and long long)
are 64-bit wide (and yes, I believe such a thing do exist.)
By the way, this is the same for C++, as strange as you believe.

The problem is that, nowadays, any Unix box (in real use, I do not
speak about the PDP-11 simulators that are used to run original
Unix V7 vintages) has 32-bit int's. So, the programs such as the
example you spoke about, are not "strictly conforming."

The solution (that I believe we used in Freetype 2, after having
playing with too many casts in Freetype 1) is usually to declare
a "Int32" type (or a similar name), that is *at*least* 32-bit wide,
and is `int' if it fits the need, else `long'. This can be detected
easily at compile time (#including <limits.h>).

C99 requires such a type, and names it "int_least32_t" (or, even
better, "int_fast32_t"), declared in <stdint.h> or <inttypes.h>.
If you are 100% sure you will always run on a POSIX-compliant OS,
you can use int32_t, but with C99 (as opposed to POSIX:2000),
note that this type is _optional_, meaning some machines (like the
one I spoke about above) can lack this typedef.

> I think this is not correct.  AFAIK, ANSI C says that `int' has *at
> least* 16 bits.  Antoine, can you give a definite answer?

You are correct. But I feel you misunderstood his words.

> groff assumes that `int' is at least 32bit.  It might be worth to add
> a test to the configure script which tests this, but honestly I doubt
> that this will ever be a problem.

Then, it means you are not writing "strictly compliant" C code (so you
cannot pretend "full ANSI compatibility".) Whether this is a problem or
not is up to you, however.

I grant you that the guy which try to use groff on a 16-bit architecture
(like Minix/86 on my Pentium, or compiling on a Mac with 16-bit int's, to
see what happens...) is in fact asking for troubles!


reply via email to

[Prev in Thread] Current Thread [Next in Thread]