Mistake on this page?
Report an issue in GitHub or email us
Macros
Toolchain functions

Macros

#define MBED_PACKED(struct)   struct __attribute__((packed))
 MBED_PACKED Pack a structure, preventing any padding from being added between fields. More...
 
#define MBED_ALIGN(N)   __attribute__((aligned(N)))
 MBED_ALIGN(N) Declare a variable to be aligned on an N-byte boundary. More...
 
#define MBED_UNUSED
 MBED_UNUSED Declare a function argument to be unused, suppressing compiler warnings. More...
 
#define MBED_USED
 MBED_USED Inform the compiler that a static variable is to be retained in the object file, even if it is unreferenced. More...
 
#define MBED_WEAK   __attribute__((weak))
 MBED_WEAK Mark a function as being weak. More...
 
#define MBED_PURE
 MBED_COMPILER_BARRIER Stop the compiler moving memory accesses. More...
 
#define MBED_NOINLINE
 MBED_NOINLINE Declare a function that must not be inlined. More...
 
#define MBED_FORCEINLINE   inline
 MBED_FORCEINLINE Declare a function that must always be inlined. More...
 
#define MBED_NORETURN
 MBED_NORETURN Declare a function that will never return. More...
 
#define MBED_UNREACHABLE   while (1)
 MBED_UNREACHABLE An unreachable statement. More...
 
#define MBED_DEPRECATED_SINCE(D, M)   MBED_DEPRECATED(M " [since " D "]")
 MBED_DEPRECATED("message string") Mark a function declaration as deprecated, if it used then a warning will be issued by the compiler possibly including the provided message. More...
 
#define MBED_CALLER_ADDR()   (NULL)
 MBED_CALLER_ADDR() Returns the caller of the current function. More...
 
#define MBED_PRETTY_FUNCTION   __PRETTY_FUNCTION__
 Macro expanding to a string literal of the enclosing function name. More...
 
#define MBED_NONSECURE_ENTRY
 MBED_NONSECURE_ENTRY Declare a function that can be called from non-secure world or secure world. More...
 

Detailed Description

Macro Definition Documentation

#define MBED_ALIGN (   N)    __attribute__((aligned(N)))

MBED_ALIGN(N) Declare a variable to be aligned on an N-byte boundary.

Note
IAR does not support alignment greater than word size on the stack
1 #include "mbed_toolchain.h"
2 
3 MBED_ALIGN(16) char a;

Definition at line 82 of file mbed_toolchain.h.

#define MBED_CALLER_ADDR ( )    (NULL)

MBED_CALLER_ADDR() Returns the caller of the current function.

Note
This macro is only implemented for GCC and ARMCC.
1 #include "mbed_toolchain.h"
2 
3 printf("This function was called from %p", MBED_CALLER_ADDR());
Returns
Address of the calling function

Definition at line 401 of file mbed_toolchain.h.

#define MBED_DEPRECATED_SINCE (   D,
 
)    MBED_DEPRECATED(M " [since " D "]")

MBED_DEPRECATED("message string") Mark a function declaration as deprecated, if it used then a warning will be issued by the compiler possibly including the provided message.

Note that not all compilers are able to display the message.

1 #include "mbed_toolchain.h"
2 
3 MBED_DEPRECATED("don't foo any more, bar instead")
4 void foo(int arg);

MBED_DEPRECATED_SINCE("version", "message string") Mark a function declaration as deprecated, noting that the declaration was deprecated on the specified version. If the function is used then a warning will be issued by the compiler possibly including the provided message. Note that not all compilers are able to display this message.

1 #include "mbed_toolchain.h"
2 
3 MBED_DEPRECATED_SINCE("mbed-os-5.1", "don't foo any more, bar instead")
4 void foo(int arg);

Definition at line 379 of file mbed_toolchain.h.

#define MBED_FORCEINLINE   inline

MBED_FORCEINLINE Declare a function that must always be inlined.

Failure to inline such a function will result in an error.

1 #include "mbed_toolchain.h"
2 
3 MBED_FORCEINLINE void foo() {
4 
5 }

Definition at line 288 of file mbed_toolchain.h.

#define MBED_NOINLINE

MBED_NOINLINE Declare a function that must not be inlined.

1 #include "mbed_toolchain.h"
2 
3 MBED_NOINLINE void foo() {
4 
5 }

Definition at line 266 of file mbed_toolchain.h.

#define MBED_NONSECURE_ENTRY

MBED_NONSECURE_ENTRY Declare a function that can be called from non-secure world or secure world.

1 #include "mbed_toolchain.h"
2 
3 MBED_NONSECURE_ENTRY void foo() {
4 
5 }

Definition at line 515 of file mbed_toolchain.h.

#define MBED_NORETURN

MBED_NORETURN Declare a function that will never return.

1 #include "mbed_toolchain.h"
2 
3 MBED_NORETURN void foo() {
4  // must never return
5  while (1) {}
6 }

Definition at line 314 of file mbed_toolchain.h.

#define MBED_PACKED (   struct)    struct __attribute__((packed))

MBED_PACKED Pack a structure, preventing any padding from being added between fields.

1 #include "mbed_toolchain.h"
2 
3 MBED_PACKED(struct) foo {
4  char x;
5  int y;
6 };

Definition at line 58 of file mbed_toolchain.h.

#define MBED_PRETTY_FUNCTION   __PRETTY_FUNCTION__

Macro expanding to a string literal of the enclosing function name.

The string returned takes into account language specificity and yield human readable content.

As an example, if the macro is used within a C++ function then the string literal containing the function name will contain the complete signature of the function - including template parameters - and namespace qualifications.

Definition at line 426 of file mbed_toolchain.h.

#define MBED_PURE

MBED_COMPILER_BARRIER Stop the compiler moving memory accesses.

The barrier stops memory accesses from being moved from one side of the barrier to the other for safety against other threads and interrupts.

This macro should only be used if we know only one CPU is accessing the data, or we are otherwise synchronising CPUs via acquire/release instructions. Otherwise, use MBED_BARRIER, which will act as a compiler barrier and also a CPU barrier if necessary.

Definition at line 245 of file mbed_toolchain.h.

#define MBED_UNREACHABLE   while (1)

MBED_UNREACHABLE An unreachable statement.

If the statement is reached, behavior is undefined. Useful in situations where the compiler cannot deduce if the code is unreachable.

1 #include "mbed_toolchain.h"
2 
3 void foo(int arg) {
4  switch (arg) {
5  case 1: return 1;
6  case 2: return 2;
7  ...
8  }
9  MBED_UNREACHABLE;
10 }

Definition at line 340 of file mbed_toolchain.h.

#define MBED_UNUSED

MBED_UNUSED Declare a function argument to be unused, suppressing compiler warnings.

1 #include "mbed_toolchain.h"
2 
3 void foo(MBED_UNUSED int arg) {
4 
5 }

Definition at line 101 of file mbed_toolchain.h.

#define MBED_USED

MBED_USED Inform the compiler that a static variable is to be retained in the object file, even if it is unreferenced.

1 #include "mbed_toolchain.h"
2 
3 MBED_USED int foo;

Definition at line 121 of file mbed_toolchain.h.

#define MBED_WEAK   __attribute__((weak))

MBED_WEAK Mark a function as being weak.

Note
Functions should only be marked as weak in the source file. The header file should contain a regular function declaration to insure the function is emitted. A function marked weak will not be emitted if an alternative non-weak implementation is defined.
Weak functions are not friendly to making code re-usable, as they can only be overridden once (and if they are multiply overridden the linker will emit no warning). You should not normally use weak symbols as part of the API to re-usable modules.
1 #include "mbed_toolchain.h"
2 
3 MBED_WEAK void foo() {
4  // a weak implementation of foo that can be overriden by a definition
5  // without __weak
6 }

Definition at line 155 of file mbed_toolchain.h.

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.