Debian lenny version packages
[pkg-perl] / deb-src / libnet-ssleay-perl / libnet-ssleay-perl-1.35 / t / local / ptr_cast_test.c
1 #include <stdlib.h>
2 #include <stdio.h>
3
4 /* test if a pointer can be cast to an unsigned long int and back
5    (aspa@hip.fi)
6
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) +
9    linux/gcc (alpha).
10
11 */
12
13 #define FROMTYPE void *
14 #define FROMTYPESTR "void *"
15 #define TOTYPE unsigned long int
16 #define TOTYPESTR "unsigned long int"
17
18 int main(argc, argv)
19      int argc; /* e.g. HP-UX cc doesn't support ISO C by default */
20      char *argv[];
21 {
22   /* heap should be near the end of process's address space */
23   FROMTYPE bufptr = (FROMTYPE) malloc(500);
24   volatile TOTYPE i; /* prevent optimization */
25
26   printf("# %s: '%s' len: %d, '%s' len: %d.\n", argv[0], FROMTYPESTR,
27          sizeof(TOTYPE), TOTYPESTR, sizeof(char *));
28
29   i = (TOTYPE)bufptr;
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");
35     exit(1);
36   } else {
37     printf("# ptr_cast_test: ok (%p == %p).\n", (FROMTYPE)i, bufptr);
38     exit(0);
39   }
40
41   exit(1);
42 }
43