1

I am sure this question has been asked before. But I am wondering what does the typedef mean in this code:

typedef long (*HASH_CONS_HASH)(void *);
typedef bool (*HASH_CONS_EQUAL(void *, void *));

So far I understand:

  • HASH_CONS_HASH is a function that takes a void* and returns long
  • HASH_CONS_EQUAL is a function that takes two arguments of type void* and returns bool

But what does typedef mean here? is it necessary?

Node.JS
  • 1,042
  • 6
  • 44
  • 114
  • You're right, it took me 10 seconds to find a LOT of questions about typedef. VTC as duplicate, duplicate, duplicate. – TomServo Jun 07 '20 at 01:04
  • The typedef allows one to use, eg, variables of the type to which any conforming function pointer can be assigned. – user2864740 Jun 07 '20 at 01:04
  • 1
    No, this question is _not_ about “typedef struct”, as a cursory reading would reveal. Voted to re-open the poor closing. (There might be other duplicates; this is not it.) – user2864740 Jun 07 '20 at 01:04

1 Answers1

1

It declares the function pointer type.

now you can define HASH_CONS_HASH func1; where func1 is a pointer to the function returning long and not taking any parameters

or HASH_CONS_EQUAL func2; where func2 is a pointer to function returning bool and taking two void pointer as parameters.

0___________
  • 60,014
  • 4
  • 34
  • 74