Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of __declspec( naked ) in gcc/g++

Tags:

c++

c

linux

gcc

g++

What is the equivalent of __declspec( naked ) in gcc/g++? __declspec( naked ) is actually used to declare a function without any epilogue and prologue.

like image 367
MetallicPriest Avatar asked Oct 29 '11 07:10

MetallicPriest


Video Answer


1 Answers

On some architectures, gcc supports an attribute called "naked"; the most recent gcc docs I have give this list of architectures: ARM, AVR, MCORE, RX and SPU.

If you are using one of those architectures (gcc will give you a warning if you try to use it and it isn't supported), the attribute can be used like this:

__attribute__ ((naked)) int fun ()
{
}

[There's been a bit of discussion recently on the gcc developer list about adding the "naked" attribute as a more general feature, and trying to support it on more architectures, but obviously that doesn't help you :).]

like image 163
snogglethorpe Avatar answered Oct 09 '22 16:10

snogglethorpe