[Yhc] Haskell Int{8,16,32...} types, config.h

Isaac isaacdupree at charter.net
Thu Aug 3 16:40:28 EDT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I decided to look in the generated "config.h" file to see what was
there. Some of it seems like it could be improved.

/* first of all get constants for Int8, Int16, Int32, etc ... */
#if SIZEOF_CHAR == 1
#  define INT8_TYPE       char
#else
#  error "can't find type matching int8"
#endif

#if SIZEOF_SHORT == 2
#  define INT16_TYPE      short
#else
#  error "can't find type matching int16"
#endif

and so on.

These are not as portable as they could be. A C standard defines headers
that have int8_t, uint8_t, int16_t, uint16_t, and so on. These types are
guaranteed by the standard, no matter what sizes "short", "int", and so
on are. This is potentially more portable across architectures, but
potentially less portable across compilers: C99 defines these headers
(both <inttypes.h> and <stdint.h>, but inttypes.h is a superset
including stuff we don't need to include). GCC has supported these
headers since a long time, but I don't know about other compilers. Using
these would also require getting rid of the hack of using macros and
attaching "unsigned" to get the unsigned version -- rather, the uintN_t
version can be used. If the headers are not available enough yet among C
compilers, the configuration could still use them "if possible".

Furthermore, since the only use (according to grep ;-)) of testing to
find out the size of various C types is in these #if SIZEOF_SHORT, etc.,
all those configuration tests would not need to be done if stdint.h or
inttypes.h was available. If we need to know the exact sizes of
floating-point types, however, we are out of luck using this route --
these are "int" headers only. Do we need to do anything with
floating-point types but distinguish "float" and "double"? It seems both
C and Haskell only offer those two named types (well, C also has "long
double" which we already ignore), and Haskell numeric literals are
always Integer or Rational, not fundamentally floating-point, so the
size of the floating-point types shouldn't affect the bytecode(?) (and
sizeof(float) and sizeof(double) can be used if the size of memory to
allocate is needed in some place in the interpreter, and various weird
properties of floats and doubles can be found in the C89 <float.h>, or
perhaps other places, if needed)

Regards,
Isaac
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.4 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFE0l87HgcxvIWYTTURAuCfAJ4gcFIHZWZWJvVs2HATQb7dNRRghACfWYi+
cHmpGdme96q5ENSYD7zE/cE=
=QLC+
-----END PGP SIGNATURE-----


More information about the Yhc mailing list