Linux内核中的C func签名:include/linux/sched.h [英] C func signature inside Linux Kernel: include/linux/sched.h

查看:67
本文介绍了Linux内核中的C func签名:include/linux/sched.h的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

再次在Linux内核中发现了这些神秘功能定义之一.该函数的签名为:

Again found once of those arcane function definitions inside linux kernel. The signature of the function reads:

static void __sched __schedule(void)

现在,它同时具有 void __ sched 作为返回类型.有人可以解释一下这些标识符在做什么.它不是void 还是 __ sched`?怎么都可以呢?

Now it has both void and __sched as the return type. Can someone please explain what those identifiers are doing there. Shouldn’t it be either voidor__sched`? How can it be both?

这是 __ sched 的定义:

 #define __sched    __attribute__((__section__(".sched.text")))

推荐答案

void 是标准的C类型,表示该函数未返回结果.

void is a standard C type, indicating that the function doesn't return a result.

__ sched 是一个宏,它根据您引用的定义扩展,从而使声明等效于:

__sched is a macro that expands in accordance with the definition you quoted, making the declaration equivalent to:

static void __attribute__((__section__(".sched.text"))) __schedule(void)

__ attribute __ 是gcc(以及与gcc兼容的编译器)支持的语言扩展.它的含义记录在 gcc手册中.它指定将函数生成的代码放置在目标文件的指定部分中.

__attribute__ is a language extension supported by gcc (and by compilers compatible with gcc). Its meaning is documented in the gcc manual. It specifies that the generated code for the function should be placed in a specified section in the object file.

由于 __ sched 或它扩展到的序列不是类型名称,因此它与 void 之间没有冲突.

Since __sched, or rather the sequence that it expands to, is not a type name, there's no conflict between it and void.

( __ attribute __ 语法中的双括号允许像这样的宏定义

(The double parentheses in the syntax of __attribute__ allow a macro definition like

#define __attribute__(arg)

如果要使用不支持该扩展名的编译器编译代码,请使用

,从而导致将其忽略而不是视为语法错误.一些属性带有多个参数.将整个参数列表包装在额外的括号中,就预处理器而言,可以将整个列表视为单个参数.)

to be used if you want to compile the code with a compiler that doesn't support that extension, causing it to be ignored rather than treated as a syntax error. Some attributes take multiple arguments; wrapping the entire argument list in an extra set of parentheses allows the entire list to be treated, as far as the preprocessor is concerned, as a single argument.)

这篇关于Linux内核中的C func签名:include/linux/sched.h的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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