MSDN中关于naked关键字的介绍:
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. Note that thenaked attribute is only valid on x86, and is not available on x64 or Itanium.
在网上搜了些资料后不是很理解,写了测试代码并反汇编了下:
#include <stdio.h>
void call_me(int x, int y)
{
int a = x;
static int b;
int c;
b = y;
c = a+b;
}
void __declspec (naked) kkk(int a, int b) {
static int c;
int d;
c = a + b;
d = c;
call_me(a, d);
}
void aaa(int a, int b) {
static int c;
int d;
c = a + b;
d = c;
call_me(a, d);
}
int main()
{
kkk(5, 6);
aaa(5, 6);
getchar();
return 1;
}
主要想看看函数编译后,函数中栈的情况变化以及nakedshu属性的函数中,进行函数调用的情况,反汇编后如下:
.text:00401000 sub_401000 proc near ; CODE XREF: .text:0040104Cp
.text:00401000 ; sub_401060+20p
.text:00401000
.text:00401000 var_8 = dword ptr -8
.text:00401000 var_4 = dword ptr -4
.text:00401000 arg_0 = dwor