简体   繁体   中英

How to create function, returning pointer to another function without typedef in C?

For example I have following functions:

char ret_a(int x)
{
    return 'a'+x;
}

typedef char (*fptr)(int);

fptr hyperfunc(float a, int b)
{
    return &ret_a;
}

How can I get rid of typedef?

You can get rid of them like this. Third function returns pointer to function which returns pointer to function which retruns char.

char ret_a(int x)
{
    return 'a'+x;
}

char (*hyperfunc(float a, int b))(int)
{
    char (*fp)(int) = &ret_a;
    return fp;
}

char (*(*superhyper(double a))(float, int))(int)
{
    char (*(*fpp)(float, int))(int)=&hyperfunc;
    return fpp;
}

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