fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define ARRAYSIZE(arr) ((sizeof(arr) != sizeof(&arr[0])) ? \
  5.   (sizeof(arr)/sizeof(*arr)) : \
  6.   -1+0*fprintf(stderr, "\n\n** pointer in ARRAYSIZE !! **\n\n"))
  7.  
  8. int main(void) {
  9.  
  10. int test[12];
  11. int* test2 = malloc(12*sizeof(int));
  12.  
  13. printf("size = %d\n", ARRAYSIZE(test));
  14. printf("size = %d\n", ARRAYSIZE(test2));
  15.  
  16. free(test2);
  17.  
  18. return 0;
  19. }
  20.  
Success #stdin #stdout #stderr 0s 2248KB
stdin
Standard input is empty
stdout
size = 12
size = -1
stderr

** pointer in ARRAYSIZE !! **