Mbed OS Reference
Loading...
Searching...
No Matches
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)   alignas(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   [[noreturn]]
 MBED_NORETURN Declare a function that will never return. More...
 
#define MBED_UNREACHABLE   while (1)
 MBED_UNREACHABLE An unreachable statement. More...
 
#define MBED_FALLTHROUGH   [[fallthrough]]
 MBED_FALLTHROUGH Marks a point in a switch statement where fallthrough can occur. 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

◆ MBED_PACKED

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

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

#include "mbed_toolchain.h"
MBED_PACKED(struct) foo {
char x;
int y;
};
#define MBED_PACKED(struct)
MBED_PACKED Pack a structure, preventing any padding from being added between fields.

Definition at line 74 of file mbed_toolchain.h.

◆ MBED_ALIGN

#define MBED_ALIGN (   N)    alignas(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
#include "mbed_toolchain.h"
MBED_ALIGN(16) char a;
#define MBED_ALIGN(N)
MBED_ALIGN(N) Declare a variable to be aligned on an N-byte boundary.

Definition at line 92 of file mbed_toolchain.h.

◆ MBED_UNUSED

#define MBED_UNUSED

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

#include "mbed_toolchain.h"
void foo(MBED_UNUSED int arg) {
}
#define MBED_UNUSED
MBED_UNUSED Declare a function argument to be unused, suppressing compiler warnings.

Definition at line 117 of file mbed_toolchain.h.

◆ MBED_USED

#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.

#include "mbed_toolchain.h"
MBED_USED int foo;
#define MBED_USED
MBED_USED Inform the compiler that a static variable is to be retained in the object file,...

Definition at line 137 of file mbed_toolchain.h.

◆ MBED_WEAK

#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.
#include "mbed_toolchain.h"
MBED_WEAK void foo() {
// a weak implementation of foo that can be overriden by a definition
// without __weak
}
#define MBED_WEAK
MBED_WEAK Mark a function as being weak.

Definition at line 171 of file mbed_toolchain.h.

◆ MBED_PURE

#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 259 of file mbed_toolchain.h.

◆ MBED_NOINLINE

#define MBED_NOINLINE

MBED_NOINLINE Declare a function that must not be inlined.

#include "mbed_toolchain.h"
MBED_NOINLINE void foo() {
}
#define MBED_NOINLINE
MBED_NOINLINE Declare a function that must not be inlined.

Definition at line 280 of file mbed_toolchain.h.

◆ MBED_FORCEINLINE

#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.

#include "mbed_toolchain.h"
MBED_FORCEINLINE void foo() {
}
#define MBED_FORCEINLINE
MBED_FORCEINLINE Declare a function that must always be inlined.

Definition at line 302 of file mbed_toolchain.h.

◆ MBED_NORETURN

#define MBED_NORETURN   [[noreturn]]

MBED_NORETURN Declare a function that will never return.

#include "mbed_toolchain.h"
MBED_NORETURN void foo() {
// must never return
while (1) {}
}
#define MBED_NORETURN
MBED_NORETURN Declare a function that will never return.

Definition at line 320 of file mbed_toolchain.h.

◆ MBED_UNREACHABLE

#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.

#include "mbed_toolchain.h"
void foo(int arg) {
switch (arg) {
case 1: return 1;
case 2: return 2;
...
}
}
#define MBED_UNREACHABLE
MBED_UNREACHABLE An unreachable statement.

Definition at line 354 of file mbed_toolchain.h.

◆ MBED_FALLTHROUGH

#define MBED_FALLTHROUGH   [[fallthrough]]

MBED_FALLTHROUGH Marks a point in a switch statement where fallthrough can occur.

Should be placed as the last statement before a label.

#include "mbed_toolchain.h"
int foo(int arg) {
switch (arg) {
case 1:
case 2:
case 3:
arg *= 2;
default:
return arg;
}
}
#define MBED_FALLTHROUGH
MBED_FALLTHROUGH Marks a point in a switch statement where fallthrough can occur.

Definition at line 380 of file mbed_toolchain.h.

◆ MBED_DEPRECATED_SINCE

#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.

#include "mbed_toolchain.h"
MBED_DEPRECATED("don't foo any more, bar instead")
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.

#include "mbed_toolchain.h"
MBED_DEPRECATED_SINCE("mbed-os-5.1", "don't foo any more, bar instead")
void foo(int arg);
#define MBED_DEPRECATED_SINCE(D, M)
MBED_DEPRECATED("message string") Mark a function declaration as deprecated, if it used then a warnin...

Definition at line 429 of file mbed_toolchain.h.

◆ MBED_CALLER_ADDR

#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.
#include "mbed_toolchain.h"
printf("This function was called from %p", MBED_CALLER_ADDR());
#define MBED_CALLER_ADDR()
MBED_CALLER_ADDR() Returns the caller of the current function.
Returns
Address of the calling function

Definition at line 449 of file mbed_toolchain.h.

◆ MBED_PRETTY_FUNCTION

#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 474 of file mbed_toolchain.h.

◆ MBED_NONSECURE_ENTRY

#define MBED_NONSECURE_ENTRY

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

#include "mbed_toolchain.h"
}
#define MBED_NONSECURE_ENTRY
MBED_NONSECURE_ENTRY Declare a function that can be called from non-secure world or secure world.

Definition at line 561 of file mbed_toolchain.h.