*************************************************************************************************************** **************
Easywave Time: 2015.02.20
Category: Linux application-GCC compiler's internal pre-macro definition and __attribute__ attribute declaration: Reprint, please keep the link
Note: If there is an error, please correct me. These are the journal articles I studied ...
*************************************************************************************************************** **************
One: the GCC compiler internal pre-macro definition under Linux
often in some open-source programs to see some macro definitions, but do not see where these macro definitions are defined, in fact, some macro definition is the cross-compiler tool GCC predefined, such as: __gnuc__,__elf__ and so on, how to see these macro definitions, You can use the following command to view it, or now look at some of the program's pre-macro definition code, as follows:
How to see these pre-macro definitions, you can use the GCC-E-dm-</dev/null command to view the following:
[email protected]:~$ gcc-e-DM-</dev/null #define __DBL_MIN_EXP__ ( -1021) #define __FLT_MIN__ 1.17549435e- 38f#define __char_bit__ 8#define __wchar_max__ 2147483647#define __gcc_have_sync_compare_and_swap_1 1#define __GCC_ have_sync_compare_and_swap_2 1#define __gcc_have_sync_compare_and_swap_4 1#define __DBL_DENORM_MIN__ 4.9406564584124654e-324#define __flt_eval_method__ 2#define __unix__ 1#define __dbl_min_10_exp__ ( -307) #define __ finite_math_only__ 0#define __gnuc_patchlevel__ 3#define __dec64_max_exp__ 385#define __SHRT_MAX__ 32767#define __LDBL _max__ 1.18973149535723176502e+4932l#define __uintmax_type__ Long Long unsigned int#define __linux 1#define __DEC32_ epsilon__ 1e-6df#define __unix 1#define __ldbl_max_exp__ 16384#define __linux__ 1#define __SCHAR_MAX__ 127#define __DBL_ dig__ 15#define _fortify_source 2#define __sizeof_int__ 4#define __sizeof_pointer__ 4#define __USER_LABEL_PREFIX__ # Define __stdc_hosted__ 1#define __ldbl_has_infinity__ 1#define __flt_epsilon__1.19209290e-7f#define __ldbl_min__ 3.36210314311209350626e-4932l#define __dec32_max__ 9.999999E96DF#define __SIZEOF _long__ 4#define __decimal_dig__ 21#define __gnu_linux__ 1#define __ldbl_has_quiet_nan__ 1#define __GNUC__ 4#define __ flt_has_denorm__ 1#define __sizeof_long_double__ 12#define __biggest_alignment__ 16#define __DBL_MAX__ 1.7976931348623157e+308#define __dbl_has_infinity__ 1#define __dec32_min_exp__ ( -94) #define __LDBL_HAS_DENORM__ Define __dec128_max__ 9.999999999999999999999999999999999e6144dl#define __dec32_min__ 1E-95DF#define __DBL_MAX_EXP_ _ 1024#define __dec128_epsilon__ 1e-33dl#define __long_long_max__ 9223372036854775807ll#define __SIZEOF_SIZE_T__ 4# Define __sizeof_wint_t__ 4#define __gxx_abi_version 1002#define __flt_min_exp__ ( -125) #define __DBL_MIN__ 2.2250738585072014e-308#define __decimal_bid_format__ 1#define __dec128_min__ 1e-6143dl#define __REGISTER_PREFIX__ # Define __dbl_has_denorm__ 1#define __no_inline__ 1#define __i386 1#define __flt_mant_dig__ 24#defiNe __version__ "4.4.3" #define __DEC64_EPSILON__ 1e-15dd#define __dec128_min_exp__ ( -6142) #define __I486__ 1#define Unix 1#define __i386__ 1#define __size_type__ unsigned int#define __elf__ 1#define __flt_radix__ 2#define __LDBL_EPSILON__ 1.0 8420217248550443401e-19l#define __sizeof_ptrdiff_t__ 4#define __dec32_subnormal_min__ 0.000001E-95DF#define __FLT_ has_quiet_nan__ 1#define __flt_max_10_exp__ 38#define __long_max__ 2147483647l#define __DEC128_SUBNORMAL_MIN__ 0.000000000000000000000000000000001e-6143dl#define __flt_has_infinity__ 1#define __DEC64_MAX__ 9.999999999999999e384dd#define __char16_type__ Short unsigned int#define __dec64_mant_dig__ 16#define __DEC32_MAX_EXP __ 97#define Linux 1#define __ldbl_mant_dig__ 64#define __dbl_has_quiet_nan__ 1#define __wchar_type__ int#define __ sizeof_float__ 4#define __dec64_min_exp__ ( -382) #define __FLT_DIG__ 6#define __int_max__ 2147483647#define __i486 Define __flt_max_exp__ 128#define __dbl_mant_dig__ 53#define __dec64_min__ 1e-383dd#define__wint_type__ unsigned int#define __sizeof_short__ 2#define __ldbl_min_exp__ ( -16381) #define __SSP__ 1#define __LDBL_ max_10_exp__ 4932#define __dbl_epsilon__ 2.2204460492503131e-16#define __sizeof_wchar_t__ 4#define __DEC_EVAL_METHOD __ 2#define __intmax_max__ 9223372036854775807ll#define __flt_denorm_min__ 1.40129846e-45f#define __CHAR32_TYPE__ unsigned int#define __flt_max__ 3.40282347e+38f#define __sizeof_double__ 8#define __flt_min_10_exp__ ( -37) #define __ intmax_type__ Long Long int#define i386 1#define __dec128_max_exp__ 6145#define __gnuc_minor__ 4#define __DEC32_MANT_DIG __ 7#define __dbl_max_10_exp__ 308#define __ldbl_denorm_min__ 3.64519953188247460253e-4951l#define __STDC__ 1#define _ _ptrdiff_type__ int#define __dec64_subnormal_min__ 0.000000000000001e-383dd#define __DEC128_MANT_DIG__ 34#define __ ldbl_min_10_exp__ ( -4931) #define __SIZEOF_LONG_LONG__ 8#define __ldbl_dig__ 18#define __gnuc_gnu_inline__ 1[email protected]:~$
In the case of embedded Linux cross-compiling GCC can also be used to view such commands, such as: arm-linux-gcc-e-DM-</dev/null command to view the following:
[email protected]:~$ arm-linux-gcc-e-DM-</dev/null#define __dbl_min_exp__ ( -1021) #define __FLT_MIN__ 1.17549435e-38f#define __dec64_den__ 0.000000000000001e-383dd#define __char_bit__ 8#define __WCHAR_MAX__ 4294967295U #define __DBL_DENORM_MIN__ 4.9406564584124654e-324#define __flt_eval_method__ 0#define __unix__ 1#define __DBL_MIN_10 _exp__ ( -307) #define __FINITE_MATH_ONLY__ 0#define __armel__ 1#define __gnuc_patchlevel__ 4#define __DEC64_MAX_EXP__ 384#define __shrt_max__ 32767#define __ldbl_max__ 1.7976931348623157e+308l#define __GXX_TYPEINFO_EQUALITY_INLINE 0# Define __uintmax_type__ Long Long unsigned int#define __linux 1#define __dec32_epsilon__ 1e-6df#define __char_unsigned__ 1#define __ldbl_max_exp__ 1024#define __linux__ 1#define __schar_max__ 127#define __DBL_DIG__ 15#define __SIZEOF_INT__ 4 #define __SIZEOF_POINTER__ 4#define __user_label_prefix__ #define __STDC_HOSTED__ 1#define __ldbl_has_infinity__ Define __FLT_EPSILON__ 1.19209290e-7f#define __apcs_32__ 1#define__ldbl_min__ 2.2250738585072014e-308l#define __dec32_max__ 9.999999e96df#define __SIZEOF_LONG__ 4#define __DECIMAL_ dig__ 17#define __gnu_linux__ 1#define __ldbl_has_quiet_nan__ 1#define __gnuc__ 4#define __FLT_HAS_DENORM__ 1#define __ sizeof_long_double__ 8#define __arm_arch_5t__ 1#define __dbl_max__ 1.7976931348623157e+308#define __DBL_HAS_INFINITY __ 1#define __dec32_min_exp__ ( -95) #define __THUMB_INTERWORK__ 1#define __ldbl_has_denorm__ 1#define __DEC128_MAX__ 9.999999999999999999999999999999999e6144dl#define __dec32_min__ 1e-95df#define __DBL_MAX_EXP__ 1024#define __DEC128 _epsilon__ 1e-33dl#define __long_long_max__ 9223372036854775807ll#define __sizeof_size_t__ 4#define __SIZEOF_WINT_T_ _ 4#define __gxx_abi_version 1002#define __softfp__ 1#define __flt_min_exp__ ( -125) #define __DBL_MIN__ 2.2250738585072014e-308#define __dec128_min__ 1e-6143dl#define __register_prefix__ #define __DBL_HAS_DENORM__ Define __no_inline__ 1#define __flt_mant_dig__ 24#define __version__ "4.3.4" #define __dec64_epsilon__ 1e-15dd#define __dec128_min_exp__ ( -6143) #define UNIX 1#define __size_type__ unsigned int#define __DEC32_ den__ 0.000001e-95df#define __elf__ 1#define __flt_radix__ 2#define __ldbl_epsilon__ 2.2204460492503131e-16L#define __ vfp_fp__ 1#define __sizeof_ptrdiff_t__ 4#define __flt_has_quiet_nan__ 1#define __flt_max_10_exp__ 38#define __LONG_MAX __ 2147483647l#define __flt_has_infinity__ 1#define __unix 1#define __dec64_max__ 9.999999999999999e384dd#define __ dec64_mant_dig__ 16#define __dec32_max_exp__ 96#define linux 1#define __dec128_den__ 0.000000000000000000000000000000001e-6143dl#define __ldbl_mant_dig__ 53#define __DBL_HAS_QUIET_NAN__ 1#define __ wchar_type__ unsigned int#define __sizeof_float__ 4#define __dec64_min_exp__ ( -383) #define __FLT_DIG__ 6#define __INT_ max__ 2147483647#define __flt_max_exp__ 128#define __dbl_mant_dig__ 53#define __dec64_min__ 1E-383DD#define __WINT_ type__ unsigned int#define __sizeof_short__ 2#define __ldbl_min_exp__ ( -1021) #define __ARM__ 1#definE __ldbl_max_10_exp__ 308#define __dbl_epsilon__ 2.2204460492503131e-16#define __sizeof_wchar_t__ 4#define __DEC_EVAL _method__ 2#define __intmax_max__ 9223372036854775807ll#define __flt_denorm_min__ 1.40129846e-45F#define __FLT_MAX__ 3.40282347e+38f#define __sizeof_double__ 8#define __flt_min_10_exp__ ( -37) #define __INTMAX_TYPE__ Long Long int#define __dec128_max_exp__ 6144#define __gnuc_minor__ 3#define __dec32_mant_dig__ 7#define __DBL_MAX_10_EXP__ 308#define __ ldbl_denorm_min__ 4.9406564584124654e-324l#define __stdc__ 1#define __ptrdiff_type__ int#define __ARM_EABI__ 1#define __dec128_mant_dig__ 34#define __ldbl_min_10_exp__ ( -307) #define __SIZEOF_LONG_LONG__ 8#define __LDBL_DIG__ 15#define _ _GNUC_GNU_INLINE__ 1
II: GCC attribute mechanism
A major feature of GNU C is the __attribute__ mechanism. The __attribute__ mechanism of the GNU C extension is used to set function properties (functions attribute), variable properties (Variable attribute), and type properties (Type attribute). __attribute__ writing features are: There are two underscores before and after the __attribute__, and the next one is immediately followed by a pair of original brackets, the corresponding __attribute__ parameters in parentheses.
__ATTRIBUTE__ syntax Format: __attribute__ ((attribute-list))
Its position constraint is: Before the tail of the Declaration ":".
function Properties (Functionattribute)
Function properties can help developers add features to function declarations, which can make the compiler more powerful in error checking. The __attribute__ mechanism is also easily compatible with non-GNU applications.
A practical example is the visibility of some functions in a dynamic library, which can be visibility to set the visibility of a function in a dynamic-link library, and if the variable or function is set to hidden, the symbol is visible only in this so and is not visible in other libraries.
GNU c at compile time, the parameter-fvisibility can be used to specify the visibility of all symbols (which are not externally visible by default); If you need to set the visibility of a particular function, you use __attribute__ in your code to set the Visibility property.
When you write a large program, you can use-fvisibility=hidden to set the symbol to be hidden by default, for specific variables and functions, using __attribute__ ((Visibility ("Default")) in your code and visible outside the symbol, This method can be used to effectively avoid symbol collisions between so.
Internal pre-macro definition and __attribute__ properties of the GCC compiler based on Linux