2 * @brief Compilers's specific attributes
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * Copyright(C) Dean Camera, 2011, 2012
\r
7 * All rights reserved.
\r
10 * Software that is described herein is for illustrative purposes only
\r
11 * which provides customers with programming information regarding the
\r
12 * LPC products. This software is supplied "AS IS" without any warranties of
\r
13 * any kind, and NXP Semiconductors and its licensor disclaim any and
\r
14 * all warranties, express or implied, including all implied warranties of
\r
15 * merchantability, fitness for a particular purpose and non-infringement of
\r
16 * intellectual property rights. NXP Semiconductors assumes no responsibility
\r
17 * or liability for the use of the software, conveys no license or rights under any
\r
18 * patent, copyright, mask work right, or any other intellectual property rights in
\r
19 * or to any products. NXP Semiconductors reserves the right to make changes
\r
20 * in the software without notification. NXP Semiconductors also makes no
\r
21 * representation or warranty that such application will be suitable for the
\r
22 * specified use without further testing or modification.
\r
25 * Permission to use, copy, modify, and distribute this software and its
\r
26 * documentation is hereby granted, under NXP Semiconductors' and its
\r
27 * licensor's relevant copyrights in the software, without fee, provided that it
\r
28 * is used in conjunction with NXP Semiconductors microcontrollers. This
\r
29 * copyright, permission, and disclaimer notice must appear in all copies of
\r
35 /** @ingroup Group_Common
\r
36 * @defgroup Group_FuncVarAttributes Function/Variable Attributes
\r
37 * @brief Special function/variable attribute macros.
\r
39 * This module contains macros for applying specific attributes to functions and variables to control various
\r
40 * optimizer and code generation features of the compiler. Attributes may be placed in the function prototype
\r
41 * or variable declaration in any order, and multiple attributes can be specified for a single item via a space
\r
44 * On incompatible versions of GCC or on other compilers, these macros evaluate to nothing unless they are
\r
45 * critical to the code's function and thus must throw a compile error when used.
\r
50 #ifndef __LPCUSBlib_FUNCATTR_H__
\r
51 #define __LPCUSBlib_FUNCATTR_H__
\r
53 /* Preprocessor Checks: */
\r
54 #if !defined(__INCLUDE_FROM_COMMON_H)
\r
55 #error Do not include this file directly. Include LPCUSBlib/Common/Common.h instead to gain this functionality.
\r
58 /* Public Interface - May be used in end-application: */
\r
60 #if (__GNUC__ >= 3) || defined(__DOXYGEN__)
\r
61 /** Indicates to the compiler that the function can not ever return, so that any stack restoring or
\r
62 * return code may be omitted by the compiler in the resulting binary.
\r
64 #define ATTR_NO_RETURN __attribute__ ((noreturn))
\r
66 /** Indicates that the function returns a value which should not be ignored by the user code. When
\r
67 * applied, any ignored return value from calling the function will produce a compiler warning.
\r
69 #define ATTR_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result))
\r
71 /** Indicates that the specified parameters of the function are pointers which should never be \c NULL.
\r
72 * When applied as a 1-based comma separated list the compiler will emit a warning if the specified
\r
73 * parameters are known at compiler time to be \c NULL at the point of calling the function.
\r
75 #define ATTR_NON_NULL_PTR_ARG(...) __attribute__ ((nonnull (__VA_ARGS__)))
\r
77 /** Removes any preamble or postamble from the function. When used, the function will not have any
\r
78 * register or stack saving code. This should be used with caution, and when used the programmer
\r
79 * is responsible for maintaining stack and register integrity.
\r
81 #define ATTR_NAKED __attribute__ ((naked))
\r
83 /** Prevents the compiler from considering a specified function for in-lining. When applied, the given
\r
84 * function will not be in-lined under any circumstances.
\r
86 #define ATTR_NO_INLINE __attribute__ ((noinline))
\r
88 /** Forces the compiler to inline the specified function. When applied, the given function will be
\r
89 * in-lined under all circumstances.
\r
91 #define PRAGMA_ALWAYS_INLINE
\r
92 #define ATTR_ALWAYS_INLINE __attribute__ ((always_inline))
\r
94 /** Indicates that the specified function is pure, in that it has no side-effects other than global
\r
95 * or parameter variable access.
\r
97 #define ATTR_PURE __attribute__ ((pure))
\r
99 /** Indicates that the specified function is constant, in that it has no side effects other than
\r
100 * parameter access.
\r
102 #define ATTR_CONST __attribute__ ((const))
\r
104 /** Marks a given function as deprecated, which produces a warning if the function is called. */
\r
105 #define ATTR_DEPRECATED __attribute__ ((deprecated))
\r
107 /** Marks a function as a weak reference, which can be overridden by other functions with an
\r
108 * identical name (in which case the weak reference is discarded at link time).
\r
110 #define PRAGMA_WEAK(func,alias)
\r
111 #define ATTR_WEAK __attribute__ ((weak))
\r
113 /** Marks a function as an alias for another function.
\r
115 * @param Func Name of the function which the given function name should alias.
\r
117 #define ATTR_ALIAS(Func) __attribute__ ((alias( #Func )))
\r
119 /** Forces the compiler to not automatically zero the given global variable on startup, so that the
\r
120 * current RAM contents is retained. Under most conditions this value will be random due to the
\r
121 * behaviour of volatile memory once power is removed, but may be used in some specific circumstances,
\r
122 * like the passing of values back after a system watchdog reset.
\r
124 #define ATTR_NO_INIT __attribute__ ((section (".noinit")))
\r
125 /** Indicates the minimum alignment in bytes for a variable or struct element.
\r
127 * @param Bytes Minimum number of bytes the item should be aligned to.
\r
129 #define PRAGMA_ALIGN_4096
\r
130 #define PRAGMA_ALIGN_2048
\r
131 #define PRAGMA_ALIGN_256
\r
132 #define PRAGMA_ALIGN_128
\r
133 #define PRAGMA_ALIGN_64
\r
134 #define PRAGMA_ALIGN_48
\r
135 #define PRAGMA_ALIGN_32
\r
136 #define PRAGMA_ALIGN_4
\r
137 #define ATTR_ALIGNED(Bytes) __attribute__ ((aligned(Bytes)))
\r
139 #define ATTR_DEPRECATED __attribute__ ((deprecated))
\r
140 #if defined (__CC_ARM)
\r
141 #define ATTR_ERROR(Message) //__attribute__ (( error(Message) ))
\r
143 #define ATTR_ERROR(Message) __attribute__ (( error(Message) ))
\r
145 #define ATTR_WARNING(Message) __attribute__ (( warning(Message) ))
\r
146 #define ATTR_IAR_PACKED
\r
147 #define ATTR_PACKED __attribute__ ((packed))
\r
150 #if defined(__ICCARM__)
\r
152 /** Indicates to the compiler that the function can not ever return, so that any stack restoring or
\r
153 * return code may be omitted by the compiler in the resulting binary.
\r
155 #define ATTR_NO_RETURN
\r
157 /** Indicates that the function returns a value which should not be ignored by the user code. When
\r
158 * applied, any ignored return value from calling the function will produce a compiler warning.
\r
160 #define ATTR_WARN_UNUSED_RESULT
\r
162 /** Indicates that the specified parameters of the function are pointers which should never be \c NULL.
\r
163 * When applied as a 1-based comma separated list the compiler will emit a warning if the specified
\r
164 * parameters are known at compiler time to be \c NULL at the point of calling the function.
\r
166 #define ATTR_NON_NULL_PTR_ARG(...)
\r
168 /** Removes any preamble or postamble from the function. When used, the function will not have any
\r
169 * register or stack saving code. This should be used with caution, and when used the programmer
\r
170 * is responsible for maintaining stack and register integrity.
\r
172 #define ATTR_NAKED __attribute__ ((naked))
\r
174 /** Prevents the compiler from considering a specified function for in-lining. When applied, the given
\r
175 * function will not be in-lined under any circumstances.
\r
177 #define ATTR_NO_INLINE __attribute__ ((noinline))
\r
179 /** Forces the compiler to inline the specified function. When applied, the given function will be
\r
180 * in-lined under all circumstances.
\r
182 #define PRAGMA_ALWAYS_INLINE _Pragma("inline=forced")
\r
183 #define ATTR_ALWAYS_INLINE
\r
185 /** Indicates that the specified function is pure, in that it has no side-effects other than global
\r
186 * or parameter variable access.
\r
188 #define ATTR_PURE __attribute__ ((pure))
\r
190 /** Indicates that the specified function is constant, in that it has no side effects other than
\r
191 * parameter access.
\r
195 /** Marks a given function as deprecated, which produces a warning if the function is called. */
\r
196 #define ATTR_DEPRECATED// __attribute__ ((deprecated))
\r
198 /** Marks a function as a weak reference, which can be overridden by other functions with an
\r
199 * identical name (in which case the weak reference is discarded at link time).
\r
201 #define _PPTOSTR_(x) #x
\r
202 #define PRAGMA_WEAK(name, vector) _Pragma(_PPTOSTR_(weak name=vector))
\r
205 /** Marks a function as an alias for another function.
\r
207 * @param Func Name of the function which the given function name should alias.
\r
209 #define ATTR_ALIAS(Func)
\r
211 /** Forces the compiler to not automatically zero the given global variable on startup, so that the
\r
212 * current RAM contents is retained. Under most conditions this value will be random due to the
\r
213 * behaviour of volatile memory once power is removed, but may be used in some specific circumstances,
\r
214 * like the passing of values back after a system watchdog reset.
\r
216 #define ATTR_NO_INIT __attribute__ ((section (".noinit")))
\r
217 /** Indicates the minimum alignment in bytes for a variable or struct element.
\r
219 * @param Bytes Minimum number of bytes the item should be aligned to.
\r
221 #define PRAGMA_ALIGN_4096 _Pragma("data_alignment=4096")
\r
222 #define PRAGMA_ALIGN_2048 _Pragma("data_alignment=2048")
\r
223 #define PRAGMA_ALIGN_256 _Pragma("data_alignment=256")
\r
224 #define PRAGMA_ALIGN_128 _Pragma("data_alignment=128")
\r
225 #define PRAGMA_ALIGN_64 _Pragma("data_alignment=64")
\r
226 #define PRAGMA_ALIGN_48 _Pragma("data_alignment=48")
\r
227 #define PRAGMA_ALIGN_32 _Pragma("data_alignment=32")
\r
228 #define PRAGMA_ALIGN_4 _Pragma("data_alignment=4")
\r
229 #define ATTR_ALIGNED(Bytes)
\r
231 //#define ATTR_DEPRECATED __attribute__ ((deprecated))
\r
233 #define ATTR_ERROR(Message)// __attribute__ (( error(Message) ))
\r
235 #define ATTR_WARNING(Message) // __attribute__ (( warning(Message) ))
\r
237 #define ATTR_IAR_PACKED __packed
\r
239 #define ATTR_PACKED
\r
243 /** Places the function in one of the initialization sections, which execute before the main function
\r
244 * of the application. Refer to the avr-libc manual for more information on the initialization sections.
\r
246 * @param SectionIndex Initialization section number where the function should be placed.
\r
248 #define ATTR_INIT_SECTION(SectionIndex) __attribute__ ((naked, section (".init" #SectionIndex )))
\r
250 /** Marks a variable or struct element for packing into the smallest space available, omitting any
\r
251 * alignment bytes usually added between fields to optimize field accesses.
\r