2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
10 /* Print the contents of a piece of memory. */
11 void hexdump (const void * start
, int size
)
14 const unsigned char * ptr
= (const unsigned char *)start
;
16 for (t
=0; size
> 0; t
++, size
--)
18 if (!(t
& 15)) printf ("%08lx: ", ((long)ptr
));
19 printf ("%02x", *ptr
++);
20 if ((t
& 3) == 3) putchar (' ');
21 if ((t
& 15) == 15) putchar ('\n');
24 if (t
& 15) putchar ('\n');
27 int main (int argc
, char ** argv
)
37 /* Store an int in a BE 16bit data type */
39 a
= c
; // Check if all conversions work
42 // Try to print the data
43 printf ("Must be 15 15 15: %d %d %d\n", a
, b
, (int)c
);
46 // Same with a pointer
49 // Note that the pointer must be casted but the compiler will print
50 // a warning if the cast is missing:
51 // warning: cannot pass objects of type `APTR' through `...'
52 // These three lines must print the same values.
53 printf ("APTR %p %p\n", &lptr
, (void *)ptr
);
54 hexdump (&ptr
, sizeof (ptr
));
55 ptr
.print (); putchar ('\n');
58 // Same with a pointer
65 // Note that the pointer must be casted but the compiler will print
66 // a warning if the cast is missing:
67 // warning: cannot pass objects of type `STRPTR' through `...'
68 // The first line must print two equal pointers and the second line
69 // must print two times "hello".
70 printf ("string %p %p\n", p1
, (void *)p2
);
71 printf ("%s %s\n", p1
, (const char *)p2
);
74 // Show the contents of the memory (to prove that the actual data is BE)
75 printf ("Contents of p1 (host endianess) and p2 (big endian):\n");
76 hexdump (&p1
, sizeof (p1
));
77 hexdump (&p2
, sizeof (p2
));
80 // Same with a structure
82 // Print address of list header
83 printf ("&lptr %p\n", &lptr
);
84 // Print list pointers (host and BE) which must be equal (otherwise the
85 // BE pointer is not converted correctly).
86 printf ("List %p %p\n", &l
, (void *)lptr
);
87 // Show that it's really a BE pointer
88 hexdump (&lptr
, sizeof (lptr
));
89 // Print the real contents of the variable in host endianess
94 // Try some functions on the list
96 printf ("NewList %p %p %p\n", (void *)(l
.lh_Head
), (void *)l
.lh_Tail
, (void *)l
.lh_TailPred
);
97 printf ("NewList %p %p %p\n", (void *)(lptr
->lh_Head
), (void *)lptr
->lh_Tail
, (void *)lptr
->lh_TailPred
);
98 hexdump (&l
, sizeof (struct List
));
102 printf ("&Node %p\n", &n
);
103 printf ("AddHead %p %p %p\n", (void *)l
.lh_Head
, (void *)l
.lh_Tail
, (void *)l
.lh_TailPred
);