Fix make-array transforms.
[sbcl.git] / tests / stack-alignment-offset.c
1 /* Compiled and run by foreign-stack-alignment.lisp
2  *
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.
7  *
8  * trampoline(int(*)()) is here so that we can get callbacks on the
9  * stack too.
10  */
11
12 /* This software is part of the SBCL system. See the README file for
13  * more information.
14  *
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.
18  *
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.
22  */
23
24 #include <stdio.h>
25 #include <stdlib.h>
26
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.
34  */
35 extern int
36 stack_alignment_offset (int alignment)
37 {
38     return ((unsigned int)&alignment) % alignment;
39 }
40
41 extern int
42 trampoline (int(*callback)(void))
43 {
44     return callback();
45 }
46
47 int main (int argc, char** argv)
48 {
49     if (argc != 2) {
50         printf("wrong number of arguments: %d\n", argc-1);
51         return 1;
52     }
53
54     printf("%d\n", stack_alignment_offset(atoi(argv[1])));
55     return 0;
56 }