AC-Archive
Autoconf Macro Archive

ac-archive.sf.net: - Project CVS - Download
Macro Index
- AM Support
- C++ Support
- C Support
- Fortran Support
- Java Support
- Cross Compilation
- Installed Packages
- Miscellaneous
- LaTeX Support
- Uncategorized
- archive macros
- adl's macros
- bkorb's macros
- guidod's macros
- latex's macros
- other's macros
- rleigh's macros
- obsoleted macros
- released macros
- search index

Documentation
- Contribute!
- History
- acincludedir m4
- acinclude (tool)
- macro howto
- ax tricks
- maintainers
- License
- Topics

generated...
2007-08-05

(C) 2007 guidod
Download the M4 Source.

ac_compile_check_sizeof

Back to the Main Page.

Synopsis
AC_COMPILE_CHECK_SIZEOF(TYPE [, HEADERS [, EXTRA_SIZES...]])
, 
Version

2000-07-19

Author

Kaveh Ghazi <ghazi@caip.rutgers.edu>

License

GPLWithACException
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. As a special exception, the respective Autoconf Macro's copyright owner gives unlimited permission to copy, distribute and modify the configure scripts that are the output of Autoconf when processing the Macro. You need not follow the terms of the GNU General Public License when using or distributing such scripts

Category

cryp.to ac-archive's Miscellaneous (released)

Documentation

This macro checks for the size of TYPE using compile checks, not run checks. You can supply extra HEADERS to look into. the check will cycle through 1 2 4 8 16 and any EXTRA_SIZES the user supplies. If a match is found, it will #define SIZEOF_`TYPE' to that value. Otherwise it will emit a configure time error indicating the size of the type could not be determined.

The trick is that C will not allow duplicate case labels. While this is valid C code:

    switch (0) case 0: case 1:;

The following is not:

    switch (0) case 0: case 0:;

Thus, the AC_TRY_COMPILE will fail if the currently tried size does not match.

Here is an example skeleton configure.in script, demonstrating the macro's usage:

    AC_PROG_CC
    AC_CHECK_HEADERS(stddef.h unistd.h)
    AC_TYPE_SIZE_T
    AC_CHECK_TYPE(ssize_t, int)

    headers='#ifdef HAVE_STDDEF_H
    #include <stddef.h>
    #endif
    #ifdef HAVE_UNISTD_H
    #include <unistd.h>
    #endif
    '

    AC_COMPILE_CHECK_SIZEOF(char)
    AC_COMPILE_CHECK_SIZEOF(short)
    AC_COMPILE_CHECK_SIZEOF(int)
    AC_COMPILE_CHECK_SIZEOF(long)
    AC_COMPILE_CHECK_SIZEOF(unsigned char *)
    AC_COMPILE_CHECK_SIZEOF(void *)
    AC_COMPILE_CHECK_SIZEOF(size_t, $headers)
    AC_COMPILE_CHECK_SIZEOF(ssize_t, $headers)
    AC_COMPILE_CHECK_SIZEOF(ptrdiff_t, $headers)
    AC_COMPILE_CHECK_SIZEOF(off_t, $headers)

M4 Source Code
AC_DEFUN([AC_COMPILE_CHECK_SIZEOF],
[changequote(&lt;&lt;, &gt;&gt;)dnl
dnl The name to #define.
define(&lt;&lt;AC_TYPE_NAME&gt;&gt;, translit(sizeof_$1, [a-z *], [A-Z_P]))dnl
dnl The cache variable name.
define(&lt;&lt;AC_CV_NAME&gt;&gt;, translit(ac_cv_sizeof_$1, [ *], [_p]))dnl
changequote([, ])dnl
AC_MSG_CHECKING(size of $1)
AC_CACHE_VAL(AC_CV_NAME,
[for ac_size in 4 8 1 2 16 $2 ; do # List sizes in rough order of prevalence.
  AC_TRY_COMPILE([#include "confdefs.h"
#include &lt;sys/types.h&gt;
$2
], [switch (0) case 0: case (sizeof ($1) == $ac_size):;], AC_CV_NAME=$ac_size)
  if test x$AC_CV_NAME != x ; then break; fi
done
])
if test x$AC_CV_NAME = x ; then
  AC_MSG_ERROR([cannot determine a size for $1])
fi
AC_MSG_RESULT($AC_CV_NAME)
AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [The number of bytes in type $1])
undefine([AC_TYPE_NAME])dnl
undefine([AC_CV_NAME])dnl
])