7 /* Print the contents of a piece of memory. */
8 void hexdump (const void * start
, int size
)
11 const unsigned char * ptr
= (const unsigned char *)start
;
13 for (t
=0; size
> 0; t
++, size
--)
15 if (!(t
& 15)) printf ("%08lx: ", ((long)ptr
));
16 printf ("%02x", *ptr
++);
17 if ((t
& 3) == 3) putchar (' ');
18 if ((t
& 15) == 15) putchar ('\n');
21 if (t
& 15) putchar ('\n');
24 int main (int argc
, char ** argv
)
34 /* Store an int in a BE 16bit data type */
36 a
= c
; // Check if all conversions work
39 // Try to print the data
40 printf ("Must be 15 15 15: %d %d %d\n", a
, b
, (int)c
);
43 // Same with a pointer
46 // Note that the pointer must be casted but the compiler will print
47 // a warning if the cast is missing:
48 // warning: cannot pass objects of type `APTR' through `...'
49 // These three lines must print the same values.
50 printf ("APTR %p %p\n", &lptr
, (void *)ptr
);
51 hexdump (&ptr
, sizeof (ptr
));
52 ptr
.print (); putchar ('\n');
55 // Same with a pointer
62 // Note that the pointer must be casted but the compiler will print
63 // a warning if the cast is missing:
64 // warning: cannot pass objects of type `STRPTR' through `...'
65 // The first line must print two equal pointers and the second line
66 // must print two times "hello".
67 printf ("string %p %p\n", p1
, (void *)p2
);
68 printf ("%s %s\n", p1
, (const char *)p2
);
71 // Show the contents of the memory (to prove that the actual data is BE)
72 printf ("Contents of p1 (host endianess) and p2 (big endian):\n");
73 hexdump (&p1
, sizeof (p1
));
74 hexdump (&p2
, sizeof (p2
));
77 // Same with a structure
79 // Print address of list header
80 printf ("&lptr %p\n", &lptr
);
81 // Print list pointers (host and BE) which must be equal (otherwise the
82 // BE pointer is not converted correctly).
83 printf ("List %p %p\n", &l
, (void *)lptr
);
84 // Show that it's really a BE pointer
85 hexdump (&lptr
, sizeof (lptr
));
86 // Print the real contents of the variable in host endianess
91 // Try some functions on the list
93 printf ("NewList %p %p %p\n", (void *)(l
.lh_Head
), (void *)l
.lh_Tail
, (void *)l
.lh_TailPred
);
94 printf ("NewList %p %p %p\n", (void *)(lptr
->lh_Head
), (void *)lptr
->lh_Tail
, (void *)lptr
->lh_TailPred
);
95 hexdump (&l
, sizeof (struct List
));
99 printf ("&Node %p\n", &n
);
100 printf ("AddHead %p %p %p\n", (void *)l
.lh_Head
, (void *)l
.lh_Tail
, (void *)l
.lh_TailPred
);