Simple illustration:
#include <stdio.h>
#include <stdlib.h>
static char SI = 0;
static int
cmp(const void *a, const void *b) { puts("CALL cmp"); if ( *(int*)a == *(int*)b ) { puts("SET SI = 1");
SI = 1; return 0; } return ( *(int*)a > *(int*)b ) ? 1 : -1;
}
int
main(int argn, char *argv[]) { int a[]={43,43};
SI = 0; qsort(a, sizeof(a)/sizeof(int), sizeof(int), cmp);
if ( SI ) puts("OK"); else puts("BUG: SI==0");
return 0;
}
% icc -O2 -o 1 1.c && ./1
CALL cmp
SET SI = 1
BUG: SI==0
% icc -O1 -o 1 1.c && ./1
CALL cmp
SET SI = 1
OK
--
Teodor Sigaev E-mail: teodor@sigaev.ru
WWW: http://www.sigaev.ru/