简体   繁体   中英

“Near initialization for…” in array of function pointers

I always did the following and I don't why but it started giving me the warning.

I'm doing:

float (*normalyze_type[5])(void) = {trap, trap, trap, filter, trap};

at the top of the .c file in order for that to be a global array of pointers.

For some reason gcc is giving me the following warnings:

 (near initialization for ‘normalize_type[0]’) [enabled by default] normalize.c ... line 13 C/C++ Problem
 (near initialization for ‘normalize_type[1]’) [enabled by default] normalize.c ... line 13 C/C++ Problem
 (near initialization for ‘normalize_type[2]’) [enabled by default] normalize.c ... line 13 C/C++ Problem
 (near initialization for ‘normalize_type[3]’) [enabled by default] normalize.c ... line 13 C/C++ Problem
 (near initialization for ‘normalize_type[4]’) [enabled by default] normalize.c ... line 13 C/C++ Problem

Already searched the internet and did not found and appropriate solution. Anyone knows how I can solve this?

Edit:

Code for the trap():

float trap( const Membership *mf, float x )
{
# define p(pIdx)        mf->parameters[ pIdx ]

if( x < p(B) )  
    return ( x - p(A) ) / ( p(B) - p(A) );

if( x > p(C) )      
    return ( p(D) - x ) / ( p(D) - p(C) );

return 1.0

#undef p
}

Code for filter():

float filter( const Membership *mf, float x )
{
if( x >= mf->parameters[threshold] )
    return x;

return 0.0;
 }

The elements of the initializer for variable normalyze_type do not have the correct type. They should have type float (*)(void) , but they actually all have type float (*)(const Membership *, float) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM