VC/C++ 裸属性有什么作用? [英] What does VC/C++ naked attribute do?

查看:20
本文介绍了VC/C++ 裸属性有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自 msdn

对于用裸体声明的函数属性,编译器生成代码没有序言和尾声代码.你可以使用此功能编写自己的prolog/epilog 代码序列使用内联汇编代码.裸函数在写作中特别有用虚拟设备驱动程序.

For functions declared with the naked attribute, the compiler generates code without prolog and epilog code. You can use this feature to write your own prolog/epilog code sequences using inline assembler code. Naked functions are particularly useful in writing virtual device drivers.

 __declspec(naked) declarator

什么是序言和尾声代码".我看到一个用 C 代码编写的库只使用 libc 在设备或固件上运行.它调用函数没有问题,naked 关键字有什么作用,为什么需要它?

What is "prolog and epilog code". I seen a libraries written in C code running on device or firmware using only libc. It calls functions without a problem, what does the naked keyword do and why is it needed?

注意:我不确定函数在这些库中使用什么调用约定.

note: I'm unsure what calling convention the functions use in those libs.

推荐答案

Prolog 和 Epilog 代码是它设置调用堆栈的第一个/最后几个指令.当您实现诸如中断例程之类的东西时,您可以使用裸体,您需要严格控制该函数中出现的确切指令.

Prolog and epilog code is the first/last few instructions where it sets up the call stack. You use naked when you're implementing something like an interrupt routine, where you need strict control over exactly what instructions appear in that function.

这篇关于VC/C++ 裸属性有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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