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.

3470 questions
795
votes
12 answers

How to display Base64 images in HTML?

I'm having trouble displaying a Base64 image inline. Can someone point me in the right direction? Display Image
Christopher
  • 8,739
  • 8
  • 28
  • 37
617
votes
15 answers

When should I write the keyword 'inline' for a function/method?

When should I write the keyword inline for a function/method in C++? After seeing some answers, some related questions: When should I not write the keyword 'inline' for a function/method in C++? When will the compiler not know when to make a…
Partial
  • 8,263
  • 12
  • 39
  • 57
443
votes
14 answers

How to write inline if statement for print?

I need to print some stuff only when a boolean variable is set to True. So, after looking at this, I tried with a simple example: >>> a = 100 >>> b = True >>> print a if b File "", line 1 print a if b ^ SyntaxError: invalid…
Ricky Robinson
  • 17,881
  • 35
  • 113
  • 172
289
votes
14 answers

Inline functions in C#?

How do you do "inline functions" in C#? I don't think I understand the concept. Are they like anonymous methods? Like lambda functions? Note: The answers almost entirely deal with the ability to inline functions, i.e. "a manual or compiler…
Dinah
  • 48,876
  • 29
  • 126
  • 149
209
votes
14 answers

When to use inline function and when not to use it?

I know that inline is a hint or request to compiler and its used to avoid function call overheads. So on what basis one can determine whether a function is a candidate for inlining or not ? In which case one should avoid inlining ?
Ashish
  • 7,621
  • 11
  • 48
  • 89
175
votes
13 answers

Are inline virtual functions really a non-sense?

I got this question when I received a code review comment saying virtual functions need not be inline. I thought inline virtual functions could come in handy in scenarios where functions are called on objects directly. But the counter-argument came…
aJ.
  • 32,074
  • 21
  • 79
  • 124
137
votes
8 answers

How can I tell gcc not to inline a function?

Say I have this small function in a source file static void foo() {} and I build an optimized version of my binary yet I don't want this function inlined (for optimization purposes). is there a macro I can add in a source code to prevent the…
vehomzzz
  • 37,854
  • 69
  • 173
  • 207
132
votes
8 answers

Why are C++ inline functions in the header?

NB This is not a question about how to use inline functions or how they work, more why they are done the way they are. The declaration of a class member function does not need to define a function as inline, it is only the actual implementation of…
thecoshman
  • 7,772
  • 5
  • 52
  • 77
131
votes
5 answers

What's the difference between "static" and "static inline" function?

IMO both make the function to have a scope of the translation unit only. What's the difference between "static" and "static inline" function? Why should inline be put in a header file, not in .c file?
new_perl
  • 6,417
  • 10
  • 36
  • 69
128
votes
1 answer

Why is this F# code so slow?

A Levenshtein implementation in C# and F#. The C# version is 10 times faster for two strings of about 1500 chars. C#: 69 ms, F# 867 ms. Why? As far as I can tell, they do the exact same thing? Doesn't matter if it is a Release or a Debug build.…
Robert Jeppesen
  • 7,671
  • 3
  • 32
  • 50
128
votes
4 answers

Does it make any sense to use inline keyword with templates?

Since templates are defined within headers and compiler is able to determine if inlining a function is advantageous, does it make any sense? I've heard that modern compilers know better when to inline a function and are ignoring inline hint. edit:…
doc
  • 7,500
  • 5
  • 42
  • 67
127
votes
4 answers

How to pass event as argument to an inline event handler in JavaScript?

// this e works document.getElementById("p").oncontextmenu = function(e) { e = e || window.event; var target = e.target || e.srcElement; console.log(target); }; // this e is undefined function doSomething(e) { e = e ||…
user1643156
  • 3,657
  • 10
  • 34
  • 58
122
votes
12 answers

Send inline image in email

Having an issue sending an image via email as an embedded image in the body. The image file shows as an attachment which is ok but the inline image portion just shows as a red x. Here is what I have so far LinkedResource inline = new…
Tsukasa
  • 5,812
  • 12
  • 53
  • 89
122
votes
2 answers

Does constexpr imply inline?

Consider the following inlined function : // Inline specifier version #include #include inline int f(const int x); inline int f(const int x) { return 2*x; } int main(int argc, char* argv[]) { return…
Vincent
  • 50,257
  • 51
  • 171
  • 339
121
votes
14 answers

Inline functions vs Preprocessor macros

How does an inline function differ from a preprocessor macro?
Subodh
  • 1,243
  • 2
  • 11
  • 8
1
2 3
99 100