[英]What does this typedef mean?
I am new to C, and this typedef looks a little bit strange to me. 我是C的新手,这种typedef对我来说有点奇怪。 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+ 您可以使用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 将alpm_cb_log声明为函数指针(alpm_loglevel_t,指向const char的指针,va_list)返回void
in this case, it is a typedef, not a declaration. 在这种情况下,它是一个typedef,而不是声明。
它将alpm_cb_log
定义为指向函数的指针的类型,该函数接受参数alpm_loglevel_t, const char *, va_list
并返回void
。
A Simple example. 一个简单的例子。 Declaration: 宣言:
typedef int myint.
Use: 采用:
myint number = 7;
myint is a synonym of int . myint是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 使用typedef的一般规则是写出一个声明,就好像你声明了你想要的类型的变量一样
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. 它是一个typedef alpm_cb_log
用于指向返回void的函数的指针,它带有两个或多个参数: alpm_loglevel_t
, const char *
和变量参数列表。
it creates the alais alpm_cb_log which is a pointer to a function that returns void and takes three paramaters. 它创建了alais alpm_cb_log,它是一个指向函数的指针,该函数返回void并占用三个参数。 1. a alpm_loglevel_t 2. const char *. 1. alpm_loglevel_t 2. const char *。 3 a varaibale argument list. 3一个varaibale参数列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.