gcc.gnu.org/onlinedocs/gcc-3.3.1/gcc/Function-Attributes.html
The keyword __attribute__ allows you to specify special attributes when making a declaration. This keyword is followed by an attribute specification inside double parentheses. The following attributes are currently defined for functions on all targets: noreturn , noinline , always_inline , pure , const , nothrow , format , format_arg , no_instrument_function , section , constructor , destructor , used , unused , deprecated , weak , malloc , alias , and nonnull . Several other attributes are defined for functions on particular target systems. Other attributes, including section are supported for variables declarations see Variable Attributes and for types see Type Attributes . You may also specify attributes with __ preceding and following each keyword. This allows you to use them in header files without being concerned about a possible macro of the same name. See Attribute Syntax , for details of the exact syntax for using attributes.
It can then optimize without regard to what would happen if fatal ever did return. More importantly, it helps avoid spurious warnings of uninitialized variables. Do not assume that registers saved by the calling function are restored before calling the noreturn function. It does not make sense for a noreturn function to have a return type other than void . The attribute noreturn is not implemented in GCC versions earlier than 25 An alternative way to declare that a function does not return, which works in the current version and in some older versions, is as follows: typedef void voidfn ;
Basically this is just slightly more strict class than the pure attribute above, since function is not allowed to read global memory. Note that a function that has pointer arguments and examines the data pointed to must not be declared const . Likewise, a function that calls a non- const function usually must not be const . The attribute const is not implemented in GCC versions earlier than 25 An alternative way to declare that a function has no side effects, which works in the current version and in some older versions, is as follows: typedef int intfn ;
For example, most functions in the standard C library can be guaranteed not to throw an exception with the notable exceptions of qsort and bsearch that take function pointer arguments. The nothrow attribute is not implemented in GCC versions earlier than 32 format archetype , string-index , first-to-check The format attribute specifies that a function takes printf , scanf , strftime or strfmon style arguments which should be type-checked against a format string.
The parameter archetype determines how the format string is interpreted, and should be printf , scanf , strftime or strfmon . You can also use __printf__ , __scanf__ , __strftime__ or __strfmon__ . The parameter string-index specifies which argument is the format string argument starting from 1, while first-to-check is the number of the first argument to check against the format string. For functions where the arguments are not available to be checked such as vprintf , specify the third parameter as zero. In this case the compiler only checks the format string for consistency. Since non-static C methods have an implicit this argument, the arguments of such methods should be counted from two, not one, when giving values for string-index and first-to-check . In the example above, the format string my_format is the second argument of the function my_print , and the arguments to check start with the third argument, so the correct parameters for the format attribute are 2 and 3. The format attribute allows you to identify your own functions which take format strings as arguments, so that GCC can check the calls to these functions for errors.
The parameter string-index specifies which argument is the format string argument starting from one. Since non-static C methods have an implicit this argument, the arguments of such methods should be counted from two. The format-arg attribute allows you to identify your own functions which modify format strings, so that GCC can check the calls to printf , scanf , strftime or strfmon type function whose operands are a call to one of your own function. The compiler always treats gettext , dgettext , and dcgettext in this manner except when strict ISO C support is requested by -ansi or an appropriate -std option, or -ffreestanding is used.
If the compiler determines that a null pointer is passed in an argument slot marked as non-null, and the -Wnonnull option is enabled, a warning is issued. The compiler may also choose to make optimizations based on the knowledge that certain function arguments will not be null. If no argument index list is given to the nonnull attribute, all pointer arguments are marked as non-null. To illustrate, the following declaration is equivalent to the previous example: extern void my_memcpy void dest, const void src, size_t len __attribute__nonnull;
This is useful when identifying functions that are expected to be removed in a future version of a program. The warning also includes the location of the declaration of the deprecated function, to enable users to easily find further information about why the function is deprecated, or what they should do instead. Note that the warnings only occurs for uses: int old_fn __attribute__ deprecated;
Unless otherwise specified by the psABI, gcc defines internal visibility to mean that the function is never called from another module. Note that hidden symbols, while they cannot be referenced directly by other modules, can be referenced indirectly via function pointers. By indicating that a symbol cannot be called from outside the module, gcc may for instance omit the load of a PIC register since it is known that the calling function loaded the correct value.
Functions that take a variable number of arguments will continue to be passed all of their arguments on the stack. Beware that on some ELF systems this attribute is unsuitable for global functions in shared libraries with lazy binding which is the default. Lazy binding will send the first call via resolving code in the loader, which might assume EAX, EDX and ECX can be clobbered, as per the standard calling conventions. GNU systems with GLIBC 21 or higher, and FreeBSD, are believed to be safe since the loaders there save all registers. Lazy binding can be disabled with the linker or the loader if desired, to avoid the problem.
Both attributes override the -mlong-calls see ARM Options command line switch and pragma long_calls settings. The long_call 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 short_call attribute always places the offset to the function from the call site into the BL instruction directly.
The compiler will generate function entry and exit sequences suitable for use in an interrupt handler when this attribute is present. Note, interrupt handlers for the H8/300, H8/300H and SH processors can be specified via the interrupt_handler attribute. 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: void f __attribute__ interrupt IRQ; Permissible values for this parameter are: IRQ, FIQ, SWI, ABORT and UNDEF.
The identifier model-name is one of small , medium , or large , representing each of the code models. Small model objects live in the lower 16MB of memory so that their addresses can be loaded with the ld24 instruction, and are callable with the bl instruction. Medium model objects may live anywhere in the 32-bit address space the compiler will generate seth/add3 instructions to load their addresses, and are callable with the bl instruction. Large model objects may live anywhere in the 32-bit address space the compiler will generate seth/add3 instructions to load their addresses, and may not be reachable with the bl instruction the compiler will generate the much slower seth/add3/jl instruction sequence.
This calling convention is also the default when using the -mlong-calls option. On 68HC12 the compiler will use the call and rtc instructions to call and re...
|