Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use int16_t, int32_t etc. #41

Open
hamogu opened this issue Jan 29, 2020 · 1 comment
Open

Use int16_t, int32_t etc. #41

hamogu opened this issue Jan 29, 2020 · 1 comment

Comments

@hamogu
Copy link
Member

hamogu commented Jan 29, 2020

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
Copy link
Member Author

hamogu commented Jan 29, 2020

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant