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

Macros

#define MBED_PACKED(struct)   struct __attribute__((packed))
 
#define MBED_ALIGN(N)   __attribute__((aligned(N)))
 
#define MBED_UNUSED
 
#define MBED_USED
 
#define MBED_WEAK   __attribute__((weak))
 
#define MBED_PURE
 
#define MBED_NOINLINE
 
#define MBED_FORCEINLINE   static inline
 
#define MBED_NORETURN
 
#define MBED_UNREACHABLE   while (1)
 
#define MBED_DEPRECATED_SINCE(D, M)   MBED_DEPRECATED(M " [since " D "]")
 
#define MBED_CALLER_ADDR()   (NULL)
 
#define MBED_PRETTY_FUNCTION   __PRETTY_FUNCTION__
 
#define MBED_PRINTF(format_idx, first_param_idx)
 
#define MBED_PRINTF_METHOD(format_idx, first_param_idx)
 
#define MBED_SCANF(format_idx, first_param_idx)
 
#define MBED_SCANF_METHOD(format_idx, first_param_idx)
 
#define MBED_FILENAME   __FILE__
 
#define WEAK   MBED_WEAK
 
#define PACKED   MBED_PACKED()
 
#define EXTERN   extern
 
#define MBED_NONSECURE_ENTRY
 

Typedefs

typedef int FILEHANDLE
 

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;
#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
#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);
#define MBED_FORCEINLINE   static 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 }
#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 }
#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 }
#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 }
typedef 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 };
#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.

#define MBED_PURE

MBED_PURE Hint to the compiler that a function depends only on parameters

1 #include "mbed_toolchain.h"
2 
3 MBED_PURE int foo(int arg){
4  // no access to global variables
5 }
#define MBED_UNREACHABLE   while (1)

MBED_UNREACHABLE An unreachable statement. If the statement is reached, behaviour is undefined. Useful in situations where the compiler cannot deduce the unreachability of code.

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