Skip to content

Commit fb27e71

Browse files
committed
Implement MBED_USED
1 parent d640472 commit fb27e71

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

platform/mbed_toolchain.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,26 @@
9292
#endif
9393
#endif
9494

95+
/** MBED_USED
96+
* Inform the compiler that a static variable is to be retained in the object file, even if it is unreferenced.
97+
*
98+
* @code
99+
* #include "mbed_toolchain.h"
100+
*
101+
* MBED_USED int foo;
102+
*
103+
* @endcode
104+
*/
105+
#ifndef MBED_USED
106+
#if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM)
107+
#define MBED_USED __attribute__((used))
108+
#elif defined(__ICCARM__)
109+
#define MBED_USED __root
110+
#else
111+
#define MBED_USED
112+
#endif
113+
#endif
114+
95115
/** MBED_WEAK
96116
* Mark a function as being weak.
97117
*

0 commit comments

Comments
 (0)