0

Can somebody please explain to me why the below code got the "invalid operands to binary ==" error?

typedef int (*func_t)(int);
#define NO_FUNC ((func_t) 0)
struct {
    const char *name;
    func_t func;
} table[] = { {"func1", NO_FUNC} };

if (table[0] == NO_FUNC) { // invalid operands to binary ==

}
2
  • Are you sure you didn't want table[0].func == NO_FUNC? Commented Oct 13, 2012 at 1:19
  • @millimoose That's what I want. Thank you. Commented Oct 13, 2012 at 1:22

2 Answers 2

3

And you should refer to the correct member in the struct:

if (table[0].func == NO_FUNC)
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, thank you. I have noticed the mistake and edited it a minute ago.
2

table[0] is of an unnamed struct type, and NO_FUNC has type int (*)(int). These two types can't be compared.

Instead, you could use:

if (table[0].func == NO_FUNC)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.