什么是“无效(* old_sigint_handler)(INT)”? [英] What is 'void (*old_sigint_handler)(int)'?

查看:225
本文介绍了什么是“无效(* old_sigint_handler)(INT)”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个语法问题。我穿越线路传来:

 无效(* old_sigint_handler)(INT);

和我不知道它在做什么。这似乎是三种类型的不带变量名的串联。我想AP preciate澄清!


解决方案

 无效(* old_sigint_handler)(INT);

这个定义 old_sigint_handler 是一个指针,它接受一个 INT 并返回无效,即没有价值。围绕括号old_sigint_handler 是必要的其他位置如下:

 无效* old_sigint_handler(INT);

声明的函数 old_sigint_handler 这需要一个 INT ,并返回一个指向无效类型。这是因为在 C 的precedence规则。括号裹紧indentifier old_sigint_handler * 使其成为一个功能,而不是一个指针的函数。阅读此精神上解析复杂的C声明 - 。顺时针/螺旋规则

This is a syntax question. I came across the line:

void (*old_sigint_handler)(int);

And I have no idea what it is doing. It seems like the concatenation of three types with no variable name. I would appreciate clarification!

解决方案

void (*old_sigint_handler)(int);

This defines old_sigint_handler to be a pointer to a function which takes an int and returns void, i.e, no value. The parentheses around old_sigint_handler are necessary here else the following:

void *old_sigint_handler(int);

declares a function old_sigint_handler which takes an int and returns a pointer to void type. This is because of the precedence rules in C. Parentheses bind tightly to the indentifier old_sigint_handler than the * making it a function rather than a pointer to a function. Read this to mentally parse complex C declaration - Clockwise/Spiral Rule.

这篇关于什么是“无效(* old_sigint_handler)(INT)”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆