Chandra-MARX / marx

Chandra X-ray Observatory ray-trace simulator
http://space.mit.edu/cxc/marx/
5 stars 4 forks source link

Use int16_t, int32_t etc. #41

Open hamogu opened 4 years ago

hamogu commented 4 years ago

Marx code predates C99, where int32_t types were codified. Instead, it uses pre-processor logic to make those definitions, e.g. in jdmath.h:

#ifdef SIZEOF_INT
# if SIZEOF_INT == 2
#  undef INT16_BASIC_TYPE
#  define INT16_BASIC_TYPE int
# else
#  if SIZEOF_INT == 4
#   undef INT32_BASIC_TYPE
#   define INT32_BASIC_TYPE int
#  endif
# endif
#endif

which says: If int is 2 bytes long, we can use int for out own type that is called INT16_BASIC_TYPE, if it is 4 bytes long, then we can use it for our own type INT32_BASIC_TYPE and in that way we build up a library of basic types. We then follow that up with:

#ifndef INT16_TYPEDEFED
# define INT16_TYPEDEFED
  typedef INT16_BASIC_TYPE int16;
  typedef unsigned INT16_BASIC_TYPE uint16;
#endif

To be clear: This approach works on all systems that we have tested and there is no urgency to address it. However, it seems a whole lot simpler to search and replace our own typedef'edint16 with int16_t from the C standard (possibly need to include <stdint.h> if that's not done yet) and add AC_TYPE_INT16_T to configure.ac.

Then, we need to test to make sure I did not overlook some subtle difference with unsigned/signed etc., but basically we should be able to cut a whole lot of pre-processor stuff out, making the code more readable.

hamogu commented 4 years ago

Once that is done, the AC_CHECK_SIZEOF_X in all three configure.ac files should also not be necessary any longer. (Not sure they are used in the code currently anywhere.)