Instead of answering “what is he doing?”, I answer “how to get him to do what I want?” There are 5 types of embedding, all available in GNU C89, C99 and C ++:
always on line if the address is not busy
Add __attribute__((always_inline)) to any ad, and then use one of the following cases to handle the possibility of receiving its address.
You probably should never use this unless you need its semantics (for example, to affect the assembly in a certain way or use alloca ). The compiler usually knows better than you if it’s worth it.
built-in and emitting a weak character (for example, C ++, it is “just make it work”)
__attribute__((weak)) void foo(void); inline void foo(void) { ... }
Note that this leaves a bunch of copies of the same code, and the linker selects one arbitrarily.
inline but never emits any character (leaving external links)
__attribute__((gnu_inline)) extern inline void foo(void) { ... }
always throw away (for one TU, to resolve the previous one)
The hint produces a weak character in C ++, but a strong character in any of the C dialects:
void foo(void); inline void foo(void) { ... }
Or you can do this without a hint that emits a strong character in both languages:
void foo(void) { ... }
Typically, you know what language your TU is in when you provide definitions, and you probably don't need to embed much.
built-in and radiating in each TU
static inline void foo(void) { ... }
For all of this, besides static , you can add the void foo(void) declaration above. This helps with the "best practice" of writing clean headers, and then #include separate file with inline definitions. Then, if C-style strings are used, #define defines the macro differently in one dedicated TU to provide definitions outside the string.
Do not forget extern "C" if the header can be used from either C or C ++!
o11c Jul 08 '18 at 7:02 2018-07-08 07:02
source share