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.
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.
It defines alpm_cb_log
to be a type for a pointer to a function that takes the arguments alpm_loglevel_t, const char *, va_list
and returns void
.
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
These do look weird if you've never seen them before. It's a typedef alpm_cb_log
for a pointer to a function returning void, taking two or more arguments: an alpm_loglevel_t
, a const char *
, and a variable argument list.
it creates the alais alpm_cb_log which is a pointer to a function that returns void and takes three paramaters. 1. a alpm_loglevel_t 2. const char *. 3 a varaibale argument list.