RE: Automake and fixed-size integer (off topic)

Caolan McNamara (Caolan.McNamara@ul.ie)
Mon, 18 Oct 1999 09:13:16 +0100 (IST)


On 17-Oct-99 Pierre Abbat wrote:
>If any of you know where I should ask this, please tell me.
>
>I'm writing a C program that should work on a variety of processors, and it
>needs to know whether the processor is big- or little-endian. I know this is
>done in configure, but I have no idea how to write a configure script. How do
>I
>do it?
>
>It also has to have structure members that are always 2 bytes, regardless of
>the processor. Someone told me __int16, but neither gcc nor egcs knows what
>that is. How do I do it?

http://www.gnu.org/manual/autoconf-2.13/html_chapter/autoconf_4.html#SEC21
For bigendian/littleendian use
AC_C_BIGENDIAN

Looking for a 16bit datatype is a bit of a pain, c itself just says that sizes
of char <= short <= int <= long.

The new single unix spec thingy says to include
<inttypes.h>
and that in that case you get
int16_t and
uint16_t

But I don't know how widespread all that it, I know that in practice that using
a short to be at least 16bits in size is save. You can get 32bit shorts but just
about everyplace I have even encountered has them at least 16bit in size. What
I do myself is assume that a char is 8 bits and that a short is at least 16 and
that an int is at least 32 and start praying. I could use the autoconf macro
AC_CHECK_SIZEOF
to work out a set of correct sizes, which is something that I have planned to do
for a while, but didnt get around to it, im sure that if I went digging in the
configure scripts of some size sensitive software that I could find ane example
reasonably easy.

One thing that you should be aware of if you are concerned with size is that
structures usually have packing space between members less that an particular
size to make them more effecient. Microsoft C doesnt have any, and microsoft
has a tendancy to write and read structures to disk. Personally I decided to
not to attempt to use pragma options to remove padding from my structures and
then to use read and write myself. I went for the slower but portably safe
reading of individual structure members byte by byte and reconstruct each member
from this with a bit of bit shifting, getting around the little/big endian
issue. (a set of awk scripts puts together most of the boiler code). Its not a
wonderful solution, but it works for now. Once everything is settled down I
intend to do speedups by (when possible) putting in pragma options to dispense
with padding and read and write complete structures, and also maybe to mmap
the file when reading and just point directly to the data in question and not
read it into a structure at all, but thats just aspirational.

C.

Real Life: Caolan McNamara * Doing: MSc in HCI
Work: Caolan.McNamara@ul.ie * Phone: +353-86-8790257
URL: http://www.csn.ul.ie/~caolan * Sig: an oblique strategy
Do we need holes?



This archive was generated by hypermail 1.03b2.