#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?
#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);