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.

ax_check_aligned_access_required

Back to the Main Page.

Synopsis
AC_CHECK_ALIGNED_ACCESS_REQUIRED
, 
Version

2006-08-17

Author

Guido U. Draheim <guidod@gmx.de>

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

guidod's C Support (released)

Documentation

While the x86 CPUs allow access to memory objects to be unaligned it happens that most of the modern designs require objects to be aligned - or they will fail with a buserror. That mode is quite known by big-endian machines (sparc, etc) however the alpha cpu is little- endian.

The following function will test for aligned access to be required and set a config.h define HAVE_ALIGNED_ACCESS_REQUIRED (name derived by standard usage). Structures loaded from a file (or mmapped to memory) should be accessed per-byte in that case to avoid segfault type errors.

M4 Source Code
AC_DEFUN([AX_CHECK_ALIGNED_ACCESS_REQUIRED],
[AC_CACHE_CHECK([if pointers to integers require aligned access],
  [ax_cv_have_aligned_access_required],
  [AC_TRY_RUN([
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

int main()
{
  char* string = malloc(40);
  int i;
  for (i=0; i &lt; 40; i++) string[[i]] = i;
  {
     void* s = string;
     int* p = s+1;
     int* q = s+2;

     if (*p == *q) { return 1; }
  }
  return 0;
}
              ],
     [ax_cv_have_aligned_access_required=yes],
     [ax_cv_have_aligned_access_required=no],
     [ax_cv_have_aligned_access_required=no])
  ])
if test "$ax_cv_have_aligned_access_required" = yes ; then
  AC_DEFINE([HAVE_ALIGNED_ACCESS_REQUIRED], [1],
    [Define if pointers to integers require aligned access])
fi
])