Ticket #7040: global-arr.c

File global-arr.c, 1.4 KB (added by nus, 3 years ago)
Line 
1#include <stdio.h>
2#include "global.h"
3
4#if defined(__MINGW32__)
5# if defined(__MINGW64_VERSION_MAJOR) && defined(__MINGW64__)
6#    define ARR_SIZE 0x0fffffff /* works when linked by ghc, fails with ghci */
7/* #    define ARR_SIZE 0x1fffffff */ /* bad executable when linked by ghc, fails to link with ghci */
8# else
9#    define ARR_SIZE 0x1 /* this, and anything bigger fails to link with ghci, works with ghc */
10# endif
11#elif defined(__APPLE__)
12# if defined(__i386__)
13#    define ARR_SIZE 0x0fffffff /* works */
14/* #    define ARR_SIZE 0x1fffffff */ /* works when linked by ghc, causes failure in malloc at ghci run-time */
15/* #    define ARR_SIZE 0x2fffffff */ /* refused by llvm-gcc as too large */
16# elif defined(__x86_64__)
17#    define ARR_SIZE 0xffffffff /* works when linked by ghc, causes failure in malloc at ghci run-time */
18# endif
19#elif defined(__linux__)
20# if defined(__i386__)
21 #    define ARR_SIZE 0x1fffffff
22/* #    define ARR_SIZE 0x2fffffff */ /* refused by gcc as too large */
23# elif defined(__x86_64__)
24/* #    define ARR_SIZE 0x1fffffff */ /* works */
25/* #    define ARR_SIZE 0x2fffffff */ /* works when linked by ghc, causes failure in malloc at ghci run-time */
26/* #    define ARR_SIZE 0x3fffffff */ /* SIGKILL'ed when linked by ghc, causes failure in malloc at ghci run-time */
27# endif
28#endif
29
30int x[ARR_SIZE];
31void printx() {
32  printf("ARR_SIZE: %x\n", ARR_SIZE);
33  x[0] = 0;
34  printf("x: %d\n", x[0]);
35  x[0] = 1;
36  printf("x: %d\n", x[0]);
37}
38