Home > Windows API > Naked functions!

Naked functions!

The compiler generates prolog and epilogue code for functions compiled for do some additional housekeeping for try/catch blocks, maintaining stack frame etc.

So what to do to prevent such code generation in MS VC compiler! MSVC compiler provides us with an attribute called __declspec(naked). Use this to prevent code generation by VC compiler.

Note that naked attribute can only be specified on function definitions and not on declarations, also it cannot be specified for data declarations!

An e.g.

__declspec(naked) void SomeFunc()
{
    // Some code
}

Well what’s the use of this! You can write your own prologue or epilogue code. MSDN also mentions that this is useful for virtual device driver development!

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: