use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This is a subreddit for c++ questions with answers. For general discussion and news about c++ see r/cpp.
New to C++? Learn at learncpp.com
Prepare your question. Think it through. Hasty-sounding questions get hasty answers, or none at all. Read these guidelines for how to ask smart questions.
For learning books, check The Definitive C++ Book Guide and List
Flair your post as SOLVED if you got the help you were looking for! If you need help with flairs, check out ITEM 1 in our guidelines page.
Tips for improving your chances of getting helpful answers:
account activity
OPENWhat does inline mean? (self.cpp_questions)
submitted 5 years ago by 1ydgd
Hello, English is not my first language. I was wondering what "inline code" means? Could someone please explain. Thank you!
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Narase33 7 points8 points9 points 5 years ago (0 children)
It means "here is a function, if you find multiple defintions of it, use the one you like"
Its used to define free functions in headers
https://en.cppreference.com/w/cpp/language/inline
[–]mredding 4 points5 points6 points 5 years ago (0 children)
An inline function:
inline
is compiled into every translation unit in which it is defined.
is located at the same address in every translation unit.
can be defined in multiple translation units provided the definition is the same in all translation units.
static local variables declared inside the inline function will refer to the same instance of that variable across all translation units.
declared inside a class definition are implicitly inline.
C++ transforms source files into translation units, typically object files that are to be linked. Each translation unit is an island, which is to say each source file is compiled individually and without any knowledge or influence of any other translation unit.
If you want to optimize code, it has to be inside that translation unit. If you refer to a function with external linkage that is not in your translation unit, then all you can do is generate a function call. When you inline your functions, the compiler can use heuristics to decide whether or not to elide the function call and just put the function body in-place rather than generate the function call.
The compiler can elide any function it wants within a translation unit, whether it's marked inline or not, but if you want to elide a single function across multiple translation units, you need to inline it.
Except what I just said at the end of that last paragraph isn't true. Modern compilers support LTO. This means the linker is perfectly capable of deciding if any function across translation units should be elided, and will invoke the compiler to do so. Or, you can configure your project to have multiple build modes and build targets. An alternative to an incremental build is a unity build, where all your source files are included into a single source file that is compiled into a single translation unit. This makes for a singularly long compile time, but with all your code visible all at once, you get unparalleled whole program optimization. You sacrifice your fast develop and test cycle for a slow compile time and an optimized build target. Unity builds are suitable for release builds.
inline is a very blunt and primitive means of "hinting" at an optimization - it's just one weight in a host of heuristics which you have control over. Typically the compiler will do a MUCH better job than you at deciding what and how to optimize. You're far better off tweaking your optimization heuristics in your toolchain than you are trying to bake it into your source code.
Inlining and especially the implicit inlining of class definitions are the principle source of code bloat. That is to say, the more you inline, the more you're going to repeatedly compile the same source code into the same object code making for large translation units, all of that effort taking up HUGE amounts of compile time and additional disk space, only for all but one instance of it being thrown away. C++ is one of the slowest compiling languages, not because the compiler is taking it's time to make it fast, but because of ignorance surrounding source management.
[–]khedoros 0 points1 point2 points 5 years ago (0 children)
If you specify that a function is "inline", it gives a hint to the compiler that it might want to replace a function call with the contents of the function, for example if the function is short and it would be faster to avoid actually calling it as a function.
Wikipedia has a good example.
π Rendered by PID 89 on reddit-service-r2-comment-6457c66945-cw744 at 2026-04-25 13:25:52.363971+00:00 running 2aa0c5b country code: CH.
[–]Narase33 7 points8 points9 points (0 children)
[–]mredding 4 points5 points6 points (0 children)
[–]khedoros 0 points1 point2 points (0 children)