1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| #include <stdio.h> #include <stdlib.h> #include <string.h>
enum tst { a1 = 0, a2, a3 = 5, a4, };
int main(int argc, const char *argv[]) { int i = 0; enum tst* test = (enum tst*)malloc(sizeof(enum tst) * 10);
printf("test=%p, sizeof enum tst=%ld\n", test, sizeof(enum tst));
for (i = 0; i < 10; i++) { test[i] = a2; } for (i = 0; i < 10; i++) { printf("test[%d]=%d\n", i, test[i]); }
printf("a1=%d, a2=%d, a3=%d, a4=%d\n", a1, a2, a3, a4);
printf("===> func: %s, line: %d\n", __func__, __LINE__); memset(test, a1, sizeof(enum tst) * 10);
for (i = 0; i < 10; i++) { printf("test[%d]=%d 0x%08x\n", i, test[i], test[i]); }
printf("===> func: %s, line: %d\n", __func__, __LINE__); memset(test, a2, sizeof(enum tst) * 10);
for (i = 0; i < 10; i++) { printf("test[%d]=%d 0x%08x\n", i, test[i], test[i]); }
printf("===> func: %s, line: %d\n", __func__, __LINE__); memset(test, a3, sizeof(enum tst) * 10);
for (i = 0; i < 10; i++) { printf("test[%d]=%d 0x%08x\n", i, test[i], test[i]); }
printf("===> func: %s, line: %d\n", __func__, __LINE__); memset(test, a4, sizeof(enum tst) * 10);
for (i = 0; i < 10; i++) { printf("test[%d]=%d 0x%08x\n", i, test[i], test[i]); } free(test);
return 0; }
|