when I call the function default_ratio_check(...), I get confusing value.
Code:
const int COMP_READ_COMPRESS = 1;
const int COMP_WRITE_COMPRESS = 0;
const int COMP_TRACE_USE_DEFAULT_RATIO = 2;
double COMP_DEFAULT_RATIO = 0.20;
compress_struct* compress_global;
double default_ratio_check( char** s, int i)
{
if( s == NULL ){
if(COMP_TRACE_USE_DEFAULT_RATIO ) {
return COMP_DEFAULT_RATIO;
}
}
if( COMP_READ_COMPRESS || COMP_WRITE_COMPRESS ){
if(COMP_TRACE_USE_DEFAULT_RATIO ) {
COMP_DEFAULT_RATIO = atof( s[i] );
return COMP_DEFAULT_RATIO;
}
}
return 0;
}
I assign the result to the double type "ratio".
Code:
ratio = default_ratio_check( (char**)0, 0 );
the value assigned to ratio is 2.0, which is the value of COMP_TRACE_USE_DEFAULT_RATIO instead of COMP_DEFAULT_RATIO. So I change the value of COMP_TRACE_USE_DEFAULT_RATIO,correspondingly, the returned value to ratio is also followed. I have use gdb to step into the function, however , I find everything works correctly. But the return value is wrong after the default_ratio_check() returned.
Thanks for your helping. gcc version 5.2.1 20151010; ubuntu 15.10