termios.h: Put some non-standard fields in a private struct.
[AROS.git] / test / uae-tmpl / test.c
blobdffa1ef7783ff78c2640202d0339e12266a742c7
3 #include <stdio.h>
4 #include "lists.h"
6 /* Print the contents of a piece of memory. */
7 void hexdump (const void * start, int size)
9 int t;
10 const unsigned char * ptr = (const unsigned char *)start;
12 for (t=0; size > 0; t++, size--)
14 if (!(t & 15)) printf ("%08lx: ", ((long)ptr));
15 printf ("%02x", *ptr++);
16 if ((t & 3) == 3) putchar (' ');
17 if ((t & 15) == 15) putchar ('\n');
20 if (t & 15) putchar ('\n');
23 int
24 main ()
26 int a;
27 short b;
28 APTR ptr;
29 WORD c;
30 struct List l;
31 ListPtr lptr;
32 struct Node n;
34 /* Store an int in a BE 16bit data type */
35 c = 15;
36 a = c; // Check if all conversions work
37 b = c;
39 // Try to print the data
40 printf ("Must be 15 15 15: %d %d %d\n", a, b, (int)c);
41 putchar ('\n');
43 // Same with a pointer
44 ptr = &lptr;
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');
53 putchar ('\n');
55 // Same with a pointer
56 char * p1;
57 STRPTR p2;
59 p1 = "hello";
60 p2 = p1;
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, (UBYTE *)p2);
69 putchar ('\n');
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));
75 putchar ('\n');
77 // Same with a structure
78 lptr = &l;
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
87 lptr.print ();
88 putchar ('\n');
89 putchar ('\n');
91 // Try some functions on the list
92 NEWLIST(lptr);
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));
96 putchar ('\n');
98 ADDHEAD(lptr, &n);
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);
101 putchar ('\n');
103 return 0;