1.0.23.58: bug 405 has been fixed a while now
[sbcl/tcr.git] / tests / stack-alignment-offset.c
blob91e5f491a01bbcd892991fec09b441c98ca1d775
1 /* Compiled and run by foreign-stack-alignment.lisp
3 * stack_alignment_offset(int) returns the offset of the first argument from a
4 * given alignment. run (1) from main, to obtain the good value with no
5 * lisp involved (2) from lisp both with and without callbacks to see that
6 * we have not messed the alignment.
8 * trampoline(int(*)()) is here so that we can get callbacks on the
9 * stack too.
12 /* This software is part of the SBCL system. See the README file for
13 * more information.
15 * While most of SBCL is derived from the CMU CL system, the test
16 * files (like this one) were written from scratch after the fork
17 * from CMU CL.
19 * This software is in the public domain and is provided with
20 * absolutely no warranty. See the COPYING and CREDITS files for
21 * more information.
24 #include <stdio.h>
25 #include <stdlib.h>
27 /* <nikodemus> bwahahahaaa!
28 * <Xophe> oh dear. He's finally flipped
29 * <lisppaste> nikodemus pasted "stack_alignment_offset" at
30 * http://paste.lisp.org/display/13231
31 * <Xophe> heh
32 * <Xophe> along with a big / * This code is really twisted * / comment :-)
33 * <antifuchs> gods.
35 extern int
36 stack_alignment_offset (int alignment)
38 return ((unsigned int)&alignment) % alignment;
41 extern int
42 trampoline (int(*callback)(void))
44 return callback();
47 int main (int argc, char** argv)
49 if (argc != 2) {
50 printf("wrong number of arguments: %d\n", argc-1);
51 return 1;
54 printf("%d\n", stack_alignment_offset(atoi(argv[1])));
55 return 0;