#include <stdio.h>
#include <malloc.h>
#include <errno.h>
#include <string.h>

static void verbose_memalign (size_t boundary, size_t size) {
  void *mem;
  errno = 0;
  mem = memalign (boundary, size);
  printf ("memalign (%5d, %5d) = %p (errno: %s)\n", boundary, size, mem, strerror (errno));
}
int
main (int   argc,
      char *argv[])
{
  int i, sizes[] = { 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536 };
  for (i = 0; i < sizeof (sizes) / sizeof (sizes[0]); i++)
    verbose_memalign (sizes[i], sizes[i] - 2 * sizeof (void*));
  return 0;
}
// compile and run: gcc -Wall aligntest.c -o aligntest && ./aligntest
