Go to main content
Oracle® Developer Studio 12.5: C User's Guide

Exit Print View

Updated: June 2017
 
 

2.10 Supported Attributes

The compiler implements the following attributes (__attribute__ ((keyword)) ) for compatibility. Spelling the attribute keyword within double underscores, __keyword__, is also accepted.

alias

Makes a name an alias for a declared function or variable name

aligned

Roughly equivalent to #pragma align. Generates a warning and is ignored if used on variable length arrays.

always_inline

Equivalent to #pragma inline and -xinline

cleanup (cleanup function)

Causes the function specified with the attribute to be executed when the associated variable goes out of scope (exits the block in which it is declared). It can be applied only to auto function scope (local) variables, and cannot be applied to parameters or variables with static storage duration. The function must take one parameter, a pointer to a type compatible with the variable. The return value of the function (if any) is ignored. It is undefined what happens if the cleanup function does not return normally.

const

Equivalent to #pragma no_side_effect

constructor

Equivalent to #pragma init, except the constructor will only be called once.

deprecated(msg)

Results in a warning if the variable or function is used anywhere in the source file. The optional argument msg must be a string and will be included in the warning message if issued.

destructor

Equivalent to #pragma fini

malloc

Equivalent to #pragma returns_new_memory

noinline

Equivalent to #pragma no_inline and -xinline

noreturn

Equivalent to #pragma does_not_return

pure

Equivalent to #pragma does_not_write_global_data

packed

Equivalent to #pragma pack()

returns_twice

Equivalent to #pragma unknown_control_flow

tls_model

Sets the thread-local storage model. The tls_model argument should be one of global-dynamic, local-dynamic, initial-exec, or local-exec.

vector_size

Indicates that a variable or a type name (created using typedef) represents a vector.

visibility

Provides linker scoping as described in Linker Scoping Specifiers. Syntax is: __attribute__((visibility(“visibility-type”))), where visibility-type is one of:

default

Same as __global linker scoping

hidden

Same as __hidden linker scoping

internal

Same as __symbolic linker scoping

weak

Equivalent to #pragma weak

2.10.1 __has_attribute function-like macro

The predefined function-like macro

__has_attribute(attr)

evaluates to 1 if attr is a supported attribute. It evaluates to 0 otherwise. Example usage:

#ifndef __has_attribute // if we don't have __has_attribute, ignore it
    #define __has_attribute(x) 0
#endif
#if __has_attribute(deprecated)
   #define DEPRECATED __attribute__((deprecated))
#else
   #define DEPRECATED // attribute "deprecated" not available
#endif
void DEPRECATED old_func(int); // use the attribute if available