I am new to C, and this typedef looks a little bit strange to me. Can someone explain what it does?
typedef void (*alpm_cb_log)(alpm_loglevel_t, const char *, va_list);
It is in a header file.
A Simple example. Declaration:
typedef int myint.
Use:
myint number = 7;
myint is a synonym of int.
your example
typedef void (*alpm_cb_log)(alpm_loglevel_t, const char *, va_list);
this is a pointer to a function
(*alpm_cb_log)
The arguments are
(alpm_loglevel_t, const char *, va_list)
and does not return anything.
void
The general rule with the use of typedef is to write out a declaration as if you were declaring variables of the types that you want
You can use cdecl.org : http://cdecl.ridiculousfish.com/?q=void+%28*alpm_cb_log%29%28alpm_loglevel_t%2C+const+char+*%2C+va_list%29+
It says:
declare alpm_cb_log as pointer to function (alpm_loglevel_t, pointer to const char, va_list) returning void
in this case, it is a typedef, not a declaration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With