# Toolchain

This module defines a toolchain abstraction layer through macros.

## Summary

Usage:

<br />

```
typedef
OT_TOOL_PACKED_BEGIN
struct
{
    char mField1;
    union
    {
        char mField2;
        long mField3;
    } OT_TOOL_PACKED_FIELD;
} OT_TOOL_PACKED_END packed_struct_t;
```

<br />

| ### Macros ||
|---|---|
| `https://openthread.io/reference/group/plat-toolchain#group__plat-toolchain_1gaa6db3390ea1a7ab5d9cc41ee92847e76 __VA_ARGS__` |   |
| `https://openthread.io/reference/group/plat-toolchain#group__plat-toolchain_1gab7d13249e3f89f28bf90650780ebd004 do \ { \ } while (false) /* fallthrough */` | Suppress fall through warning in specific compiler. |
| `https://openthread.io/reference/group/plat-toolchain#group__plat-toolchain_1ga78619f2131e14bb383ef31d5a56bdbc4` | Compiler-specific indication that a class or struct is a resource owner for lifetime safety analysis. |
| `https://openthread.io/reference/group/plat-toolchain#group__plat-toolchain_1ga067d4d11c7e7b84560bd8af7edbbf4c4` | Compiler-specific indication that a class or struct is a non-owning view or pointer for lifetime safety analysis. |
| `https://openthread.io/reference/group/plat-toolchain#group__plat-toolchain_1gaaeff20b2666903cddb27860cf45ca707` | Compiler-specific indication that a function or method return value's lifetime is bound to a parameter or `this`. |
| `https://openthread.io/reference/group/plat-toolchain#group__plat-toolchain_1ga85de426d72fe7c26a0fa927ed51db39d` | Compiler-specific indication that a class or enum must be used when it is the return value of a function. |
| `https://openthread.io/reference/group/plat-toolchain#group__plat-toolchain_1gae629cb38422619fa287047f5d859d872` | Compiler-specific indication that a pointer or reference parameter does not escape the function scope. |
| `https://openthread.io/reference/group/plat-toolchain#group__plat-toolchain_1gaa846557e3320c6c3a8a0448f1d1f0bab` |   |
| `https://openthread.io/reference/group/plat-toolchain#group__plat-toolchain_1ga5d2b35a947d54bcbd4e9f539e8dad768` |   |
| `https://openthread.io/reference/group/plat-toolchain#group__plat-toolchain_1gaba6ad63129c3a790957a9b149a65891b` | Compiler-specific indication that a class or struct must be byte packed. |
| `https://openthread.io/reference/group/plat-toolchain#group__plat-toolchain_1ga3a18bfefd8517f5653568f3b8423ed40` | Indicate to the compiler a nested struct or union to be packed within byte packed class or struct. |
| `https://openthread.io/reference/group/plat-toolchain#group__plat-toolchain_1gabe6a7eade7833871637a0c4efe629404` | Specifies that a function or method takes `printf` style arguments and should be type-checked against a format string. |
| `https://openthread.io/reference/group/plat-toolchain#group__plat-toolchain_1gafa4fa6f7590e3c3c45f69d2f9f1bca43` | Compiler-specific weak symbol modifier. |
| `https://openthread.io/reference/group/plat-toolchain#group__plat-toolchain_1gab3be7baad123fa22d83d942794fe71d7 CODE` | Suppress Unreachable code warning in specific toolchains. |
| `https://openthread.io/reference/group/plat-toolchain#group__plat-toolchain_1ga1f82d697553f7df5589668e481738e8c do \ { \ (void)(VARIABLE); \ } while (false)` | Suppress unused variable warning in specific toolchains. |

## Macros

### OT_APPLE_IGNORE_GNU_FOLDING_CONSTANT

```
 OT_APPLE_IGNORE_GNU_FOLDING_CONSTANT __VA_ARGS__
```

### OT_FALL_THROUGH

```
 OT_FALL_THROUGH do                  \
    {                   \
    } while (false) /* fallthrough */
```
Suppress fall through warning in specific compiler.

### OT_GSL_OWNER

```
 OT_GSL_OWNER
```
Compiler-specific indication that a class or struct is a resource owner for lifetime safety analysis.

### OT_GSL_POINTER

```
 OT_GSL_POINTER
```
Compiler-specific indication that a class or struct is a non-owning view or pointer for lifetime safety analysis.

### OT_LIFETIME_BOUND

```
 OT_LIFETIME_BOUND
```
Compiler-specific indication that a function or method return value's lifetime is bound to a parameter or `this`.

### OT_MUST_USE_RESULT

```
 OT_MUST_USE_RESULT
```
Compiler-specific indication that a class or enum must be used when it is the return value of a function.

<br />

> [!NOTE]
> **Note:** This is currently only available with clang (C++17 implements it as attribute \[\[nodiscard\]\]).

> [!NOTE]
> **Note:** To suppress the 'unused-result' warning/error, please use the '-Wno-unused-result' compiler option.

<br />

### OT_NOESCAPE

```
 OT_NOESCAPE
```
Compiler-specific indication that a pointer or reference parameter does not escape the function scope.

### OT_SUPPRESS_GCC_STRING_OP_BEGIN

```
 OT_SUPPRESS_GCC_STRING_OP_BEGIN
```

### OT_SUPPRESS_GCC_STRING_OP_END

```
 OT_SUPPRESS_GCC_STRING_OP_END
```

### OT_TOOL_PACKED_BEGIN

```
 OT_TOOL_PACKED_BEGIN
```
Compiler-specific indication that a class or struct must be byte packed.

### OT_TOOL_PACKED_FIELD

```
 OT_TOOL_PACKED_FIELD
```
Indicate to the compiler a nested struct or union to be packed within byte packed class or struct.

### OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK

```
 OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK
```
Specifies that a function or method takes `printf` style arguments and should be type-checked against a format string.

Must be added after the function/method declaration. For example:

`void MyPrintf(void *aObject, const char *aFormat, ...) https://openthread.io/reference/group/plat-toolchain#group__plat-toolchain_1gabe6a7eade7833871637a0c4efe629404;`

The two argument index values indicate format string and first argument to check against it. They start at index 1 for the first parameter in a function and at index 2 for the first parameter in a method.

<br />

Details Parameters `[in] aFmtIndex` The argument index of the format string. `[in] aStartIndex` The argument index of the first argument to check against the format string.

### OT_TOOL_WEAK

```
 OT_TOOL_WEAK
```
Compiler-specific weak symbol modifier.

### OT_UNREACHABLE_CODE

```
 OT_UNREACHABLE_CODE CODE
```
Suppress Unreachable code warning in specific toolchains.

### OT_UNUSED_VARIABLE

```
 OT_UNUSED_VARIABLE do                               \
    {                                \
        (void)(VARIABLE);            \
    } while (false)
```
Suppress unused variable warning in specific toolchains.

## Resources

OpenThread API Reference topics originate from the source code, available on [GitHub](https://github.com/openthread/openthread/tree/main/include/openthread). For more information, or to contribute to our documentation, refer to [Resources](https://openthread.io/resources).