Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this typedef mean?

Tags:

c

typedef

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.

like image 624
yasar Avatar asked Nov 30 '22 06:11

yasar


2 Answers

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

like image 25
user1138677 Avatar answered Dec 15 '22 16:12

user1138677


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.

like image 145
J-16 SDiZ Avatar answered Dec 15 '22 14:12

J-16 SDiZ