Are the functions defined in the headers guaranteed?

If I define a function other than the member in the header, will it always be embedded in the compiler, or does the compiler select based on its heuristic? I know __inline is just a hint, is it the same with functions in the headers?

+5
source share
5 answers

Remember that including any of the headings is no different than simply entering them directly in the source file. Thus, getting into the header has nothing to do with the compiler; he never knew what it was.

Therefore, when you define a function in the header file and include this header file in the file, it looks like you just typed the function directly into the file. So, now the question arises: "does the compiler select built-in things based on heuristics?"

Answer: "it depends on the compiler." The standard does not give any guarantees as to what is included in the composition or not. However, any modern compiler will be extremely smart in that it is probably built in with heuristics.

. , , . , , . Ergo, . ( : ", x, y" ). , inline, ODR.

, __inline . , , , . inline - , inlining. , , - .

+11

++ FAQ Lite:

, inline, , : - , .

+4

. , inline , , .

+2

, (: linker erorr) (ODR). , "": inlining ODR. , , , .

, ( static, ), inline.

... ( ), , , ​​ inline .

+2

. , . ( / , , )

"inline":

, ++: inline, -, .

-

  • , , , .
  • .

inlining, , - , , , . , . , , "inline".

inlining, , . . , , . , , , , . , , , " ". , , , , , . .

+1

All Articles