⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 function-attributes.html

📁 gcc手册
💻 HTML
📖 第 1 页 / 共 3 页
字号:
     <br><dt><code>stdcall</code>

     <dd>On the Intel 386, the <code>stdcall</code> attribute causes the compiler to

assume that the called function will pop off the stack space used to

pass arguments, unless it takes a variable number of arguments.



     <p>The PowerPC compiler for Windows NT currently ignores the <code>stdcall</code>

attribute.



     <br><dt><code>cdecl</code>

     <dd>On the Intel 386, the <code>cdecl</code> attribute causes the compiler to

assume that the calling function will pop off the stack space used to

pass arguments.  This is

useful to override the effects of the <code>-mrtd</code> switch.



     <p>The PowerPC compiler for Windows NT currently ignores the <code>cdecl</code>

attribute.



     <br><dt><code>longcall/shortcall</code>

     <dd>On the RS/6000 and PowerPC, the <code>longcall</code> attribute causes the

compiler to always call this function via a pointer, just as it would if

the <code>-mlongcall</code> option had been specified.  The <code>shortcall</code>

attribute causes the compiler not to do this.  These attributes override

both the <code>-mlongcall</code> switch and the <code>#pragma longcall</code>

setting.



     <p>See <a href="RS-6000-and-PowerPC-Options.html#RS%2f6000%20and%20PowerPC%20Options">RS/6000 and PowerPC Options</a>, for more information on when long

calls are and are not necessary.



     <br><dt><code>long_call/short_call</code>

     <dd>This attribute allows to specify how to call a particular function on

ARM.  Both attributes override the <code>-mlong-calls</code> (see <a href="ARM-Options.html#ARM%20Options">ARM Options</a>)

command line switch and <code>#pragma long_calls</code> settings.  The

<code>long_call</code> attribute causes the compiler to always call the

function by first loading its address into a register and then using the

contents of that register.   The <code>short_call</code> attribute always places

the offset to the function from the call site into the <code>BL</code>

instruction directly.



     <br><dt><code>dllimport</code>

     <dd>On the PowerPC running Windows NT, the <code>dllimport</code> attribute causes

the compiler to call the function via a global pointer to the function

pointer that is set up by the Windows NT dll library.  The pointer name

is formed by combining <code>__imp_</code> and the function name.



     <br><dt><code>dllexport</code>

     <dd>On the PowerPC running Windows NT, the <code>dllexport</code> attribute causes

the compiler to provide a global pointer to the function pointer, so

that it can be called with the <code>dllimport</code> attribute.  The pointer

name is formed by combining <code>__imp_</code> and the function name.



     <br><dt><code>exception (</code><var>except-func</var><code> [, </code><var>except-arg</var><code>])</code>

     <dd>On the PowerPC running Windows NT, the <code>exception</code> attribute causes

the compiler to modify the structured exception table entry it emits for

the declared function.  The string or identifier <var>except-func</var> is

placed in the third entry of the structured exception table.  It

represents a function, which is called by the exception handling

mechanism if an exception occurs.  If it was specified, the string or

identifier <var>except-arg</var> is placed in the fourth entry of the

structured exception table.



     <br><dt><code>function_vector</code>

     <dd>Use this attribute on the H8/300 and H8/300H to indicate that the specified

function should be called through the function vector.  Calling a

function through the function vector will reduce code size, however;

the function vector has a limited size (maximum 128 entries on the H8/300

and 64 entries on the H8/300H) and shares space with the interrupt vector.



     <p>You must use GAS and GLD from GNU binutils version 2.7 or later for

this attribute to work correctly.



     <br><dt><code>interrupt</code>

     <dd>Use this attribute on the ARM, AVR, M32R/D and Xstormy16 ports to indicate

that the specified function is an interrupt handler.  The compiler will

generate function entry and exit sequences suitable for use in an

interrupt handler when this attribute is present.



     <p>Note, interrupt handlers for the H8/300, H8/300H and SH processors can

be specified via the <code>interrupt_handler</code> attribute.



     <p>Note, on the AVR interrupts will be enabled inside the function.



     <p>Note, for the ARM you can specify the kind of interrupt to be handled by

adding an optional parameter to the interrupt attribute like this:



     <pre class="smallexample">          void f () __attribute__ ((interrupt ("IRQ")));

          </pre>



     <p>Permissible values for this parameter are: IRQ, FIQ, SWI, ABORT and UNDEF.



     <br><dt><code>interrupt_handler</code>

     <dd>Use this attribute on the H8/300, H8/300H and SH to indicate that the

specified function is an interrupt handler.  The compiler will generate

function entry and exit sequences suitable for use in an interrupt

handler when this attribute is present.



     <br><dt><code>sp_switch</code>

     <dd>Use this attribute on the SH to indicate an <code>interrupt_handler</code>

function should switch to an alternate stack.  It expects a string

argument that names a global variable holding the address of the

alternate stack.



     <pre class="smallexample">          void *alt_stack;

          void f () __attribute__ ((interrupt_handler,

                                    sp_switch ("alt_stack")));

          </pre>



     <br><dt><code>trap_exit</code>

     <dd>Use this attribute on the SH for an <code>interrupt_handle</code> to return using

<code>trapa</code> instead of <code>rte</code>.  This attribute expects an integer

argument specifying the trap number to be used.



     <br><dt><code>eightbit_data</code>

     <dd>Use this attribute on the H8/300 and H8/300H to indicate that the specified

variable should be placed into the eight bit data section. 

The compiler will generate more efficient code for certain operations

on data in the eight bit data area.  Note the eight bit data area is limited to

256 bytes of data.



     <p>You must use GAS and GLD from GNU binutils version 2.7 or later for

this attribute to work correctly.



     <br><dt><code>tiny_data</code>

     <dd>Use this attribute on the H8/300H to indicate that the specified

variable should be placed into the tiny data section. 

The compiler will generate more efficient code for loads and stores

on data in the tiny data section.  Note the tiny data area is limited to

slightly under 32kbytes of data.



     <br><dt><code>signal</code>

     <dd>Use this attribute on the AVR to indicate that the specified

function is an signal handler.  The compiler will generate function

entry and exit sequences suitable for use in an signal handler when this

attribute is present.  Interrupts will be disabled inside function.



     <br><dt><code>naked</code>

     <dd>Use this attribute on the ARM, AVR and IP2K ports to indicate that the

specified function do not need prologue/epilogue sequences generated by

the compiler.  It is up to the programmer to provide these sequences.



     <br><dt><code>model (</code><var>model-name</var><code>)</code>

     <dd>Use this attribute on the M32R/D to set the addressability of an object,

and the code generated for a function. 

The identifier <var>model-name</var> is one of <code>small</code>, <code>medium</code>,

or <code>large</code>, representing each of the code models.



     <p>Small model objects live in the lower 16MB of memory (so that their

addresses can be loaded with the <code>ld24</code> instruction), and are

callable with the <code>bl</code> instruction.



     <p>Medium model objects may live anywhere in the 32-bit address space (the

compiler will generate <code>seth/add3</code> instructions to load their addresses),

and are callable with the <code>bl</code> instruction.



     <p>Large model objects may live anywhere in the 32-bit address space (the

compiler will generate <code>seth/add3</code> instructions to load their addresses),

and may not be reachable with the <code>bl</code> instruction (the compiler will

generate the much slower <code>seth/add3/jl</code> instruction sequence).



     <br><dt><code>far</code>

     <dd>On 68HC11 and 68HC12 the <code>far</code> attribute causes the compiler to

use a calling convention that takes care of switching memory banks when

entering and leaving a function.  This calling convention is also the

default when using the <code>-mlong-calls</code> option.



     <p>On 68HC12 the compiler will use the <code>call</code> and <code>rtc</code> instructions

to call and return from a function.



     <p>On 68HC11 the compiler will generate a sequence of instructions

to invoke a board-specific routine to switch the memory bank and call the

real function. The board-specific routine simulates a <code>call</code>. 

At the end of a function, it will jump to a board-specific routine

instead of using <code>rts</code>. The board-specific return routine simulates

the <code>rtc</code>.



     <br><dt><code>near</code>

     <dd>On 68HC11 and 68HC12 the <code>near</code> attribute causes the compiler to

use the normal calling convention based on <code>jsr</code> and <code>rts</code>. 

This attribute can be used to cancel the effect of the <code>-mlong-calls</code>

option.



   </dl>



   <p>You can specify multiple attributes in a declaration by separating them

by commas within the double parentheses or by immediately following an

attribute declaration with another attribute declaration.



   <p>Some people object to the <code>__attribute__</code> feature, suggesting that

ISO C's <code>#pragma</code> should be used instead.  At the time

<code>__attribute__</code> was designed, there were two reasons for not doing

this.



     <ol type=1 start=1>

<li>It is impossible to generate <code>#pragma</code> commands from a macro.



     <li>There is no telling what the same <code>#pragma</code> might mean in another

compiler.

        </ol>



   <p>These two reasons applied to almost any application that might have been

proposed for <code>#pragma</code>.  It was basically a mistake to use

<code>#pragma</code> for <em>anything</em>.



   <p>The ISO C99 standard includes <code>_Pragma</code>, which now allows pragmas

to be generated from macros.  In addition, a <code>#pragma GCC</code>

namespace is now in use for GCC-specific pragmas.  However, it has been

found convenient to use <code>__attribute__</code> to achieve a natural

attachment of attributes to their corresponding declarations, whereas

<code>#pragma GCC</code> is of use for constructs that do not naturally form

part of the grammar.  See <a href="../cpp/Other-Directives.html#Other%20Directives">Miscellaneous Preprocessing Directives</a>.



   </body></html>



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -