Posted on 2008-09-28 10:17
没画完的画 阅读(336)
评论(0) 编辑 收藏 引用 所属分类:
VC
1. naked function
裸函数, vc特有语法, 一旦在函数加上 __declspec(naked) 声明,
编译器不会给函数加上任何优化和汇编语句
即, 你需要自己用汇编语句实现读取参数(如果有参数的话)
到最好还要用 ret 来返回, 声明语法
void __declspec(naked) MyNakedFunction()
{
_asm
{
}
}
注: 1. 只能用于声明函数,不能修饰变量
2. 不能用于函数前向声明, 前向声明时需要把 __declspec(naked) 去掉, 即写成 void MyNakedFunction();
在函数体才加上 __declspec(naked)
From MSDN
Functions declared with the naked attribute are emitted without prolog or epilog code, enabling you to write your own custom prolog/epilog
sequences using the inline assembler. Naked functions are provided as an advanced feature. They enable you to declare a function that is
being called from a context other than C/C++, and thus make different assumptions about where parameters are, or which registers are
preserved. Examples include routines such as interrupt handlers. This feature is particularly useful for writers of virtual device drivers
(VxDs). ers (VxDs).
-------------------------------------------------------------------------------------------------------------------------------------------------