Search code examples
ctypedef

What does `typedef` mean in this context


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?


Solution

  • 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.