Inline and outline finctions.... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Inline and outline finctions....

What happens when we use inline and outline functions? Does it make any changes in memory ? And what about compilation?

13th Aug 2018, 6:06 AM
nirmites
nirmites - avatar
6 Answers
+ 4
Every couple of years a new C++ version comes out, C++17 is the one from 2017
13th Aug 2018, 9:07 AM
Schindlabua
Schindlabua - avatar
+ 3
hinanawi That's what it used to do but it turns out compilers know better when to inline code than humans.. So `inline` went from inlining code, to being a recommendation to inline code in newer C++ versions, and as of C++17 inline has nothing to do with inlining anymore, it's about linkage. From cpprererence.com: "There may be more than one definition of an inline function or variable (since C++17) in the program as long as each definition appears in a different translation unit and (for non-static inline functions and variables) all definitions are identical. For example, an inline function or an inline variable may be defined in a header file that is #include'd in multiple source files." I haven't needed to use it for anything, personally.
13th Aug 2018, 7:18 AM
Schindlabua
Schindlabua - avatar
+ 1
when a function is marked as inline, during compilation, instances of the function call are replaced with the contents of the function. this helps with speed a bit in some cases
13th Aug 2018, 7:01 AM
hinanawi
hinanawi - avatar
+ 1
Schindlabua yea, most of the time you wouldn't explicitly mark a function as "inline", you let the compiler decide. also i've not ever used c++17 so it's interesting to see that it's been changed
13th Aug 2018, 7:22 AM
hinanawi
hinanawi - avatar
+ 1
nirmites when your function code is small, you request compiler to make it inline by putting inline keyword... if it's inline, your function call doesn't happen by linking function call with function pointer.. rather compiler replaces code of function at place of function call.. this reduces function call overhead. this is differece between inline and normal function.. Please note that you can request to compiler for making it inline.. it's compiler which decides whether to make function inline or not.. compiler can ignore your request or even make function inline evenif you have not mentioned it as inline
13th Aug 2018, 7:36 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
What is C++17, tell in description...
13th Aug 2018, 8:57 AM
nirmites
nirmites - avatar