On configure systems

I will never understand the point of using autotools, cmake or whatever configure system, when later the code uses an hardcoded list of architectures to determine the size of a pointer… Unfortunately for porters this pattern is quite common.

Update: As people keep asking, the way to check for the size of a given type is explained in the autoconf manual. To check for the size of the pointer, the following entry has to be added to configure.ac:

AC_CHECK_SIZEOF(void *)

On a 64-bit system, this will lead to the following entry in config.h:

/* The size of `void *', as computed by sizeof. */
#define SIZEOF_VOID_P 8

5 Responses to “On configure systems”

  • Consider it a potential for teaching. Where can one learn about pointer-size detection with autotools? Also, it might point to a specific deficit in autotool’s documentation or implementation?

    I read your post as implying that pointer-size detection is much easier using the configuration system instead of using a bunch of #defines, but is that really so?

  • Gregor says:

    The downside of putting such things in (publically visible) header files is that they differ across architectures and need some extra handling during packaging.

    Shouldn’t the preprocessor be able to provide exactly the same information?

    • aurel32 says:

      There are indeed some way to check that using the preprocessor, but they are not fully portable. When using only GCC, one can check the preprocessor built-in __SIZEOF_POINTER__. Alternatively it should be possible to check if UINTPTR_MAX matches the value of UINT64_MAX, but for that you need a C99 compliant compiler.

  • Christian Seiler says:

    Why would you even need a define for that? sizeof(void *) is a compile-time constant and can even be used where only constant expressions are allowed (for array lengths for fixed-size structs etc.). For integers that can be converted to pointers and back there’s intptr_t. So why bother with defines and/or configure-stuff at all? Or am I missing something really obvious?

    (btw. sizeof(char) is always exactly 1 according to the C standard, still I’ve seen countless configure runs that actually check for that…)

    • aurel32 says:

      I agree that in theory it should not be needed to do that. That said in most of the case I have seen it concerns pre C99 code (especially for compatiblity with old versions of MSVC), which doesn’t know about intptr_t and need a way to know how to cast between pointers and ints. It also concerns codes which redefine all types to internal names, or more legitimaly atomic code which need to know which atomic gcc built-in to call.


Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>