6912af29963e5ece01ad3dfde2c99003c5001ac2
[libfirm] / ir / be / test / fehler35.c
1 #include <stdio.h>
2 #include <assert.h>
3
4 unsigned int p0 = 0;
5 unsigned int p1 = 42;
6
7 int simpler(void)
8 {
9         if (p0 != p1)
10                 if (p0  == 0)
11                         return -1;
12                 else
13                         return 1;
14         return 0;
15 }
16
17 int compare_string(char *CompValue, char         *ValuePtr)
18 {
19     int              i           = 0;
20     unsigned char   *p0          = (unsigned char *)CompValue;
21     unsigned char   *p1          = (unsigned char *)ValuePtr;
22
23     /*  Compare the string pointed to by CompValue
24         against    string pointed to by ValuePtr                              */
25 #if 0
26     if (DeBug)
27         if (sprintf  (Msg, "    Ut_CompareString:: <%-24s> To <%-24s>;\n",
28                     p0, p1))
29             TraceMsg (0, Msg);
30 #endif
31
32     for (i = 0; i == 0 && *p0 != NULL && *p1 != NULL; p0++, p1++)
33     {
34         if (*p0 != *p1)
35             if (*p0  < *p1)
36                 i      = -1;
37             else
38                 i      = 1;
39     }
40
41     if (i    == 0)
42         if (*p0  != *p1)
43             if (*p0  == NULL)
44                 i      = -1;
45             else
46                 i      = 1;
47
48 #if 0
49     if (ClassBug && !SetBug)
50         if (sprintf  (Msg,  "  Ut_Compare::      <%-16s> To <%-16s>; i = %d\n",
51                     CompValue, ValuePtr, i))
52             TraceMsg (0, Msg);
53 #endif
54
55     return(i);
56 }
57
58 int main()
59 {
60 #define test(a,b,shouldbe)   { int res = compare_string(a, b); printf("Compare %s, %s -> %d (should be %d)\n", a, b, res, shouldbe); assert(res == shouldbe); }
61         test("a", "b", -1);
62         test("", "", 0);
63         test("Rothe", "Rother", -1);
64         test("hallo", "hallo", 0);
65         test("hallo", "welt", -1);
66         test("welt", "hallo", 1);
67
68         printf("Simpler: %d\n", simpler());
69         return 0;
70 }