Benefits of declaring a function as “inline”?

前端 未结 10 1884
天涯浪人
天涯浪人 2020-12-09 14:01

Every time I read about the \"inline\" declaration in C it is mentioned that it is only a hint to the compiler (i.e. it does not have to obey it). Is there any benefit to ad

10条回答
  •  攒了一身酷
    2020-12-09 14:41

    Since it's only a hint to the compiler, the compiler is free to ignore it, and likely will. The compiler has a lot of relevant information you don't have, such as how much of a cache line a loop will take up, and can inline or not on a case-by-case basis.

    It's just a hint, so using it is unlikely to hurt anything. You almost certainly should avoid any compiler-specific things that force functions to be inlined or not inlined.

提交回复
热议问题