Questions tagged [inline]

Use this tag for questions specifically about the effects of the inline keyword, together with the appropriate language tag.

Inline, or inline expansion, is a programming language optimization that inserts the complete body of the function in every place that the function is called. Depending on the programming language, this may be implemented by the compiler, manually or by a keyword.

Historically, in the C and C++ programming languages, an inline function is a function upon which the compiler has been requested to perform inline expansion. In other words, the programmer has requested that the compiler insert the complete body of the function in every place that the function is called, rather than generating code to call the function in the one place it is defined. However, modern compilers usually use their own heuristics and ignore the request. Thus, the inline keyword is now mostly used for its effects on the One Definition Rule.

Inline expansion is used to eliminate the time overhead when a function is called. It is typically used for functions that execute frequently. It also has a space benefit for very small functions, and is an enabling transformation for other optimizations.

3753 questions
38
votes
2 answers

Display a few words in different colors in Flutter

I am writing an application which shows a few words in different colors in flutter. I tried to load HTML files using the plugin flutter_html_view but that one doesn't support styles(inline). I also tried to use markdown. How can I achieve this?
Caffeinatedwolf
  • 1,217
  • 3
  • 20
  • 26
37
votes
6 answers

What's the scope of inline friend functions?

After searching aroung SO, one question taught me that the lexical scope of an inline friend function is the class it's defined in, meaning it can access e.g. the typedefs in the class without qualifying them. But then I wondered what is the actual…
Xeo
  • 129,499
  • 52
  • 291
  • 397
37
votes
3 answers

Inline functions - what are they exactly vis-a-vis the inline keyword?

In this link, what is an inline function and what is the inline keyword is explained. I'm reading through it because I realized I've never understood the meaning of these two concepts and how they should be used in practice. I'm quoting and…
user8469759
  • 2,522
  • 6
  • 26
  • 50
37
votes
8 answers

(How) Can I inline a particular function call?

Let's say that I have a function that gets called in multiple parts of a program. Let's also say that I have a particular call to that function that is in an extremely performance-sensitive section of code (e.g., a loop that iterates tens of…
fouric
  • 1,598
  • 1
  • 19
  • 37
36
votes
9 answers

Can I selectively (force) inline a function?

In the book Clean Code (and a couple of others I have come across and read) it is suggested to keep the functions small and break them up if they become large. It also suggests that functions should do one thing and one thing only. In Optimizing…
Samaursa
  • 16,527
  • 21
  • 89
  • 160
36
votes
4 answers

Does GCC inline C++ functions without the 'inline' keyword?

Does GCC, when compiling C++ code, ever try to optimize for speed by choosing to inline functions that are not marked with the inline keyword?
Carl Seleborg
  • 13,125
  • 11
  • 58
  • 70
35
votes
6 answers

Why are class member functions inlined?

I think my question has been asked here before, I did read them but still little confused and therefore asking to make it clear. The C++ standard says all member functions defined inside class definition are inline I have also heard that compiler…
vidit
  • 6,293
  • 3
  • 32
  • 50
35
votes
4 answers

display:block inside display:inline

I want to understand what happens when an element whose CSS is display:block is a DOM child of an element whose CSS is display:inline (so that the block element is a child of an inline element). This scenarios is described in the Anonymous block…
ChrisW
  • 54,973
  • 13
  • 116
  • 224
33
votes
5 answers

inline function linker error

I am trying to use inline member functions of a particular class. For example the function declaration and implementation without inlining is as such: in the header file: int GetTplLSize(); in the .cpp file: int NeedleUSsim::GetTplLSize() { …
stanigator
  • 10,768
  • 34
  • 94
  • 129
32
votes
1 answer

Difference between an inline function and static inline function

Can anybody tell me what the difference is between an inline function and static inline function? In which cases should I prefer static inline over inline? I am asking this question because I have an inline function for which I am facing compilation…
Vijay
  • 65,327
  • 90
  • 227
  • 319
31
votes
4 answers

C++ can compilers inline a function pointer?

Suppose I've got a function functionProxy that takes a generic parameter function and call its operator(): template< typename Function > void functionProxy( Function function ) { function(); } The object passed to it may be: a functor: struct…
peoro
  • 25,562
  • 20
  • 98
  • 150
31
votes
3 answers

How to force-save an "empty"/unchanged django admin inline?

I have some inlines in one of my admin models which have default values which likely won't need to be changed when adding a new instance with "Add another ...". Unfortunately django won't recognize these inline as new objects unless some value has…
Daniel
  • 1,197
  • 8
  • 13
30
votes
4 answers

Why does defining inline global function in 2 different cpp files cause a magic result?

Suppose I have two .cpp files file1.cpp and file2.cpp: // file1.cpp #include inline void foo() { std::cout << "f1\n"; } void f1() { foo(); } and // file2.cpp #include inline void foo() { std::cout <<…
Narek Atayan
  • 1,479
  • 13
  • 27
30
votes
2 answers

Static, extern and inline in Objective-C

What do static, extern and inline (and their combinations) mean in Objetive-C using the LLVM compiler? Also, I noticed that there are CG_EXTERN and CG_INLINE macros. Should we be using those instead? (I couldn't find a source with a clear…
hpique
  • 119,096
  • 131
  • 338
  • 476
29
votes
10 answers

should I take arguments to inline functions by reference or value?

Is one of these faster? inline int ProcessByValue(int i) { // process i somehow } inline int ProcessByReference(const int& i) { // process i somehow } I know that integral types should be passed by value. However, I am concerned that the…
rlbond
  • 65,341
  • 56
  • 178
  • 228