# Smarter C/C++ inlining with \_\_attribute\_\_((flatten))

DevFeed: [Smarter C/C++ inlining with \_\_attribute\_\_((flatten))](<https://devfeed.tech/articles/smarter-c-c-inlining-with-attribute-flatten-38362.md>)

Original publisher: [Read original article](<https://awesomekling.github.io/Smarter-C++-inlining-with-attribute-flatten/>)

Author: Andreas Kling

Published: 2020-04-27T00:00:00Z

Content type: tutorial

Language: en

Sources: [Andreas Kling](<https://devfeed.tech/sources/andreas-kling.md>)

Topics: [inlining](<https://devfeed.tech/topics/inlining.md>), [c/c++](<https://devfeed.tech/topics/c-c-plus-plus.md>), [Optimization](<https://devfeed.tech/topics/optimization.md>), [clang](<https://devfeed.tech/topics/clang.md>), [gcc](<https://devfeed.tech/topics/gcc.md>), [build times](<https://devfeed.tech/topics/build-times.md>)

Tags: [build-times](<https://devfeed.tech/tags/build-times.md>), [c-c-plus-plus](<https://devfeed.tech/tags/c-c-plus-plus.md>), [clang](<https://devfeed.tech/tags/clang.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [cpp](<https://devfeed.tech/tags/cpp.md>), [function](<https://devfeed.tech/tags/function.md>), [gcc](<https://devfeed.tech/tags/gcc.md>), [inlining](<https://devfeed.tech/tags/inlining.md>), [optimization](<https://devfeed.tech/tags/optimization.md>), [performance](<https://devfeed.tech/tags/performance.md>), [technical](<https://devfeed.tech/tags/technical.md>)

## AI overview

This post explains how to use the __attribute__((flatten)) function attribute in C/C++ to apply aggressive inlining selectively. GCC and Clang support the attribute, which inlines a function's callees while limiting the program-size, cache-locality, and build-time costs of broader inlining.

## Source excerpt

This post describes a compile-time technique for getting the benefits of aggressive inlining in hot code while protecting cool code from its downsides.