开发者

How do return an enum in a typedef of function pointer?

#include <stdio.h>

enum bool
{
  true, false
};

typedef bool
(*compare_fun) (int, int);

I get an error when I enter the above开发者_开发问答 code. How do I make a function pointer that needs to return a boolean?


it should be typedef enum bool (*compare_fun)(int, int); :)

Also make sure your implementation doesn't have predefined bool true and false

Note that in C++ when you define an enum, class or struct, say with name A, then you can declare a variable of type A like

A var;

or

class A var; //or struct A var; or enum A var;

in C, only the second syntax is valid. That's why they usually make a typedef. like this

typedef enum {true, false} bool;

in this case you can use your original syntax :

typedef bool (*p) (int, int);

HTH.


What about:

typedef enum 
{
    true, false
} bool;

bool
(*compare_fun) (int, int);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜