NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: lib/37943: posix_memalign doesn't work

The following reply was made to PR lib/37943; it has been noted by GNATS.

From: Magnus Henoch <>
Subject: Re: lib/37943: posix_memalign doesn't work
Date: Sun, 03 Feb 2008 16:22:15 +0100

 It seems the alignment is still incorrect, though.  Using the extended
 test program below, I get:
 % ./posix_memalign_test 4096 8192 8184
 posix_memalign(&a, 8192, 8184): 0x1813000
 0x1813000 % 8192 = 4096
 #include <stdio.h>
 #include <stdlib.h>
 int main(int argc, char *argv[])
   char *a;
   int n;
   size_t size, alignment, prealloc;
   if (argc != 4) {
     printf("Usage: %s PREALLOC ALIGNMENT SIZE\n", argv[0]);
     return 1;
   sscanf(argv[1], "%d", &prealloc);
   sscanf(argv[2], "%d", &alignment);
   sscanf(argv[3], "%d", &size);
   n = posix_memalign(&a, alignment, size);
   if (n)
     printf("posix_memalign(&a, %d, %d): %p\n", alignment, size, a);
   *a = 'a';
   printf("%p %% %d = %d\n", a, alignment, (int)a % alignment);  
   return 0;

Home | Main Index | Thread Index | Old Index