4 ms·
`inline` indicates to the compiler: "this function has external linkage, and no matter how many times it's defined it is to be defined only once in the final li
by pbsd 12y ago
`inline` indicates to the compiler: "this function has external linkage, and no matter how many times it's defined it is to be defined only once in the final linked output". It's the same as if there was no inline, but when the linker finds multiple definitions of the same function it is allowed to ignore them instead of failing. It also serves as a inlining hint to the compiler in its free time.
Note that you don't necessarily have to type `inline` to have inline functions. Methods defined in the declaration of a class are implicitly inline; so are template functions (but not explicit specializations).
The reason it's called `inline` instead of something else probably has something to do with the committee's aversion to new keywords, and commitment to backwards compatibility. Changing `static` would probably break a lot of code: think what would happen to static variables inside static functions.
- mtdewcmu 12y ago'static' is old. It must have meant something to Kernighan and Ritchie. I see no connection to the word inline in the C++ meaning. In C, at least, inline means inline. My guess is that the C++ inline got its meaning from the winding path of c++ history, and only makes sense in the context of that history.
- geon 12y agoI guess it is that in C++, methods implemented in the class declaration are implicitly "inline". It could be done to avoid the problem outlined above.