4 /* test if a pointer can be cast to an unsigned long int and back
7 tested on: HP-UX B.10.20, AIX 4.3, IRIX 5.3, OSF1 v4.0B and SunOS 5.6
8 with both gcc and native compilers, and linux/gcc (i686) +
13 #define FROMTYPE void *
14 #define FROMTYPESTR "void *"
15 #define TOTYPE unsigned long int
16 #define TOTYPESTR "unsigned long int"
19 int argc; /* e.g. HP-UX cc doesn't support ISO C by default */
22 /* heap should be near the end of process's address space */
23 FROMTYPE bufptr = (FROMTYPE) malloc(500);
24 volatile TOTYPE i; /* prevent optimization */
26 printf("# %s: '%s' len: %d, '%s' len: %d.\n", argv[0], FROMTYPESTR,
27 sizeof(TOTYPE), TOTYPESTR, sizeof(char *));
30 if( ((FROMTYPE)i) != bufptr ) {
31 printf("# %s: failed: (%p != %p).\n", argv[0], (FROMTYPE)i, bufptr);
32 printf("# ERROR: a '%s' can't be cast to a '%s' and back \n",
33 FROMTYPESTR, TOTYPESTR);
34 printf("# ERROR: without loss of information on this architecture.\n");
37 printf("# ptr_cast_test: ok (%p == %p).\n", (FROMTYPE)i, bufptr);