Chris Lattner | 38c4272 | 2002-07-14 23:48:42 +0000 | [diff] [blame^] | 1 | |
| 2 | |
| 3 | void *malloc(unsigned); |
| 4 | |
| 5 | //#include <stdio.h> |
| 6 | int puts(const char *s); |
| 7 | |
| 8 | struct FunStructTest { |
| 9 | int Test1; |
| 10 | char *Pointer; |
| 11 | int Array[12]; |
| 12 | }; |
| 13 | |
| 14 | struct SubStruct { |
| 15 | short X, Y; |
| 16 | }; |
| 17 | |
| 18 | struct Quad { |
| 19 | int w; |
| 20 | struct SubStruct SS; |
| 21 | struct SubStruct *SSP; |
| 22 | char c; |
| 23 | int y; |
| 24 | }; |
| 25 | |
| 26 | struct Quad GlobalQuad = { 4, {1, 2}, 0, 3, 156 }; |
| 27 | |
| 28 | typedef int (*FuncPtr)(int); |
| 29 | |
| 30 | unsigned PtrFunc(int (*Func)(int), int X) { |
| 31 | return Func(X); |
| 32 | } |
| 33 | |
| 34 | char PtrFunc2(FuncPtr FuncTab[30], int Num) { |
| 35 | return FuncTab[Num]('b'); |
| 36 | } |
| 37 | |
| 38 | extern char SmallArgs2(char w, char x, long long Zrrk, char y, char z); |
| 39 | extern int SomeFunc(void); |
| 40 | char SmallArgs(char w, char x, char y, char z) { |
| 41 | SomeFunc(); |
| 42 | return SmallArgs2(w-1, x+1, y, z, w); |
| 43 | } |
| 44 | |
| 45 | static int F0(struct Quad Q, int i) { /* Pass Q by value */ |
| 46 | struct Quad R; |
| 47 | if (i) R.SS = Q.SS; |
| 48 | Q.SSP = &R.SS; |
| 49 | Q.w = Q.y = Q.c = 1; |
| 50 | return Q.SS.Y + i + R.y - Q.c; |
| 51 | } |
| 52 | |
| 53 | int F1(struct Quad *Q, int i) { /* Pass Q by address */ |
| 54 | struct Quad R; |
| 55 | #if 0 |
| 56 | if (i) R.SS = Q->SS; |
| 57 | #else |
| 58 | if (i) R = *Q; |
| 59 | #endif |
| 60 | Q->w = Q->y = Q->c = 1; |
| 61 | return Q->SS.Y+i+R.y-Q->c; |
| 62 | } |
| 63 | |
| 64 | |
| 65 | int BadFunc(float Val) { |
| 66 | int Result; |
| 67 | if (Val > 12.345) Result = 4; |
| 68 | return Result; /* Test use of undefined value */ |
| 69 | } |
| 70 | |
| 71 | int RealFunc(void) { |
| 72 | return SomeUndefinedFunction(1, 4, 5); |
| 73 | } |
| 74 | |
| 75 | extern int EF1(int *, char *, int *); |
| 76 | |
| 77 | int Func(int Param, long long Param2) { |
| 78 | int Result = Param; |
| 79 | |
| 80 | {{{{ |
| 81 | char c; int X; |
| 82 | EF1(&Result, &c, &X); |
| 83 | }}} |
| 84 | |
| 85 | { // c & X are duplicate names! |
| 86 | char c; int X; |
| 87 | EF1(&Result, &c, &X); |
| 88 | } |
| 89 | |
| 90 | } |
| 91 | return Result; |
| 92 | } |
| 93 | |
| 94 | |
| 95 | short FunFunc(long long x, char z) { |
| 96 | return x+z; |
| 97 | } |
| 98 | |
| 99 | unsigned castTest(int X) { return X; } |
| 100 | |
| 101 | double TestAdd(double X, float Y) { |
| 102 | return X+Y+.5; |
| 103 | } |
| 104 | |
| 105 | int func(int i, int j) { |
| 106 | while (i != 20) |
| 107 | i += 2; |
| 108 | |
| 109 | j += func(2, i); |
| 110 | return (i * 3 + j*2)*j; |
| 111 | } |
| 112 | |
| 113 | int SumArray(int Array[], int Num) { |
| 114 | int i, Result = 0; |
| 115 | for (i = 0; i < Num; ++i) |
| 116 | Result += Array[i]; |
| 117 | |
| 118 | return Result; |
| 119 | } |
| 120 | |
| 121 | int ArrayParam(int Values[100]) { |
| 122 | return EF1((int*)Values[50], (char*)1, &Values[50]); |
| 123 | } |
| 124 | |
| 125 | int ArrayToSum(void) { |
| 126 | int A[100], i; |
| 127 | for (i = 0; i < 100; ++i) |
| 128 | A[i] = i*4; |
| 129 | |
| 130 | return A[A[0]]; //SumArray(A, 100); |
| 131 | } |
| 132 | |
| 133 | |
| 134 | int ExternFunc(long long, unsigned*, short, unsigned char); |
| 135 | |
| 136 | int main(int argc, char *argv[]) { |
| 137 | unsigned i; |
| 138 | puts("Hello world!\n"); |
| 139 | |
| 140 | ExternFunc(-1, 0, (short)argc, 2); |
| 141 | //func(argc, argc); |
| 142 | |
| 143 | for (i = 0; i < 10; i++) |
| 144 | puts(argv[3]); |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | double MathFunc(double X, double Y, double Z, |
| 149 | double AA, double BB, double CC, double DD, |
| 150 | double EE, double FF, double GG, double HH, |
| 151 | double aAA, double aBB, double aCC, double aDD, |
| 152 | double aEE, double aFF) { |
| 153 | return X + Y + Z + AA + BB + CC + DD + EE + FF + GG + HH |
| 154 | + aAA + aBB + aCC + aDD + aEE + aFF; |
| 155 | } |
| 156 | |
| 157 | |
| 158 | |
| 159 | void strcpy(char *s1, char *s2) { |
| 160 | while (*s1++ = *s2++); |
| 161 | } |
| 162 | |
| 163 | void strcat(char *s1, char *s2) { |
| 164 | while (*s1++); |
| 165 | s1--; |
| 166 | while (*s1++ = *s2++); |
| 167 | } |
| 168 | |
| 169 | int strcmp(char *s1, char *s2) { |
| 170 | while (*s1++ == *s2++); |
| 171 | if (*s1 == 0) { |
| 172 | if (*s2 == 0) { |
| 173 | return 0; |
| 174 | } else { |
| 175 | return -1; |
| 176 | } |
| 177 | } else { |
| 178 | if (*s2 == 0) { |
| 179 | return 1; |
| 180 | } else { |
| 181 | return (*(--s1) - *(--s2)); |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | |