1. 程式人生 > >C語言學習筆記--__attribute__概述

C語言學習筆記--__attribute__概述

    GNU C 的一大特色就是__attribute__ 機制。__attribute__ 可以設定函式屬性(Function Attribute )、變數屬性(Variable Attribute )和型別屬性(Type Attribute )。
    語法格式:__attribute__ ((attribute-list)) attribute前後都有兩個下劃線,並切後面會緊跟一對原括弧,括弧裡面是相應的__attribute__ 引數。
    位置:放於宣告的尾部“ ;” 之前。
    1、函式屬性(Function Attribute)  函式屬性可以把一些特性新增到函式宣告中,從而可以使編譯器在錯誤檢查方面的功能更強大。
    noreturn
    noinline
    always_inline
    pure
    const
    nothrow
    sentinel
    format
    format_arg
    no_instrument_function
    section
    constructor
    destructor
    used
    unused
    deprecated
    weak
    malloc
    alias
    warn_unused_result
    nonnull
    2、型別屬性(Type Attributes):
    aligned
    packed
    transparent_union,
    unused,
    deprecated
    may_alias
   3、變數屬性(Variable Attribute):
    aligned
    packed
   4、Clang特有:
    availability
    overloadable