fork(1) download
  1. #include <stdio.h>
  2.  
  3. #define ASIZE(a) (sizeof (a) / sizeof((a)[0]))
  4. #define GET_COMPATIBLE_ARRAY_PTR_TYPE( a ) __typeof__((a)[0])(*)[ASIZE(a)]
  5. #define GET_CHECKING_FUNC_PTR_TYPE( a ) void (*)(GET_COMPATIBLE_ARRAY_PTR_TYPE( a ))
  6. #define CHECK_ARRAY_SEGFAULT( a ) ((GET_CHECKING_FUNC_PTR_TYPE( a ))NULL)(&(a))
  7.  
  8. int main(void)
  9. {
  10. short a[3];
  11. short *b;
  12. int c[2];
  13. int *d;
  14. long long e[5][4];
  15. char *f[4];
  16. char (*g)[4];
  17. (void)a; (void)b; (void)c; (void)d; (void)e; (void)f; (void)g;
  18. printf("CHECK_ARRAY_SEGFAULT() only 'accepts' arrays (try uncommenting).\n");
  19. CHECK_ARRAY_SEGFAULT( a );
  20. //CHECK_ARRAY_SEGFAULT( b );
  21. CHECK_ARRAY_SEGFAULT( c );
  22. //CHECK_ARRAY_SEGFAULT( d );
  23. CHECK_ARRAY_SEGFAULT( e );
  24. //CHECK_ARRAY_SEGFAULT( f );
  25. //CHECK_ARRAY_SEGFAULT( g );
  26. return 0;
  27. }
  28.  
Runtime error #stdin #stdout 0s 2112KB
stdin
Standard input is empty
stdout
Standard output is empty