/* * ({ statement }) ;Return the value of statement * typeof() ;Return the type of expression * __extension__ ;Disable pedantic warnings * (void) (&_x == &_y) ;If X,Y is not the same type, * there will be a warning */ #define min(X,Y) / (__extension__ / ({/ typeof(X) _x = (X);/ typeof(Y) _y = (Y); / (void) (&_x == &_y); / (_x < _y) ? _x : _y;/ }) ) /* Old version of min */ #define MIN(X,Y) ((X) < (Y) ? (X) : (Y)); #include<stdio.h> int main(){ int a = 2, b = 1, c = 0; c = min(a++, b++); printf("%d, %d, %d/n", a, b ,c); a = 2, b = 1, c = 0; c = MIN(a++, b++); printf("%d, %d, %d/n", a, b ,c); min(a, 2.2);/* Here warning */ } /* * Zero-length array * in variable-length structure */ #include<stdio.h> #include<string.h> #include<stdlib.h> struct shit{ int a; char name[0]; }; int main(){ struct shit *shitp = (struct shit *) malloc(sizeof(struct shit)+ sizeof(char)*35); shitp -> a = 23; strcpy(shitp -> name, "abceef"); printf("%d/n%s/n", shitp -> a, shitp -> name); } /************************************************* +---------+ |____1____| shit.a |____2____| |____3____| |____4____| |____5____| shit.name |____6____| |____7____| . . . **************************************************/ /* * Extention of Switch: * case allows to specify a continous range of values */ #include<stdio.h> int main(){ int d; scanf("%d", &d); switch(d){ case 0 ... 100 : printf("In 100/n"); break; case 101 ... 200 : printf("In 200/n");break; case 201 ... 900 : printf("In 900/n"); break; default : printf("shit/n"); } } /* * Array or structure initialization */ #include<stdio.h> #include<string.h> struct sss{ int a; int b; int c; char e; char k; }; int main(){ int k; scanf("%d", &k); char b[k]; /* Notice this */ strcpy(b, "sheet yop/n"); printf("%s", b); struct sss a = { 1,2,3,'f','k'}; printf("%d,%d,%d, %c,%c/n", a.a, a.b, a.c, a.e, a.k); int arr[100] = {[0] = 34, [33] = 89, [56 ... 90] = 9}; for(k = 0; k < 100; k++) printf("%d,", arr[k]); } /* I DON'T KNOW */ #include<stdio.h> int main(){ void *ptr; ptr = &&abc; int a = 1; abc: printf("1%d,%p:/n",a,ptr); printf("2%d,%p:/n",a,ptr); printf("3%d,%p:/n",a,ptr); ptr = &&abc + (void *)1000; goto *ptr; } /* * Token paste operator : ## # */ #define k(a,b,c) a ##_##c##?B##b #define e(a) #a int main(){ k(ef,kb,ll); /*ef_ll?Bkb*/ e(k(ef,ee,ss)); /* "k(ef,ee,ss))" */ } /*asm inline */ #include<stdio.h> int main(){ char *a = "sdfa"; char *b; int c = a; __asm__ ("movl %1,%0":"=r"(b):"m"(a)); printf("%s",b); }