I was reading about inline functions in C++ , and mostly what I understood was that the compiler will copy paste the function code which is inlined. If an inline function contains a return statement and the function is used in some other function will it cause the caller function to terminate and return?
As an example consider
inline int foo(void) {
return 1;
}
int bar(void) {
//Some statements
foo()
//Some more statements
return 2;
}
Will the foo()
in bar(
) return before bar reaches return 2;
line because the code is copy-pasted by compiler? Else how is the return statement handled in inline functions? I do understand that this will not break the code flow now, but how is the return statement handled if the code is copy-pasted or inlined?
Inline functions are more than a simple copy-paste procedure (in contrast to, say, preprocessor macros). They behave like normal functions, so any return value would be reflected to the caller just like a normal function.