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
26
votes
11 answers

When do compilers inline C++ code?

In C++, do methods only get inlined if they are explicitly declared inline (or defined in a header file), or are compilers allowed to inline methods as they see fit?
Tony the Pony
  • 40,327
  • 71
  • 187
  • 281
26
votes
5 answers

Inline keyword vs header definition

What's the difference between using the inline keyword before a function and just declaring the whole function in the header? so... int whatever() { return 4; } vs .h: inline int whatever(); .cpp: inline int myClass::whatever() { return…
Dollarslice
  • 9,917
  • 22
  • 59
  • 87
25
votes
1 answer

Why do global inline variables and static inline members in C++17 need guards?

Since C++17 it's possible to initialize global variables and static members in headers using the inline keyword. While I understand why static variables in functions need to be guarded (because initialization should happen only once even in a…
John Lettehw
  • 251
  • 2
  • 4
25
votes
1 answer

Why is "inline" required on static inline variables?

C++17 allows static member variables to be defined thus: class X { public: static inline int i = 8; }; What is the rationale behind requiring the inline specification? Why not simply allow programmers to write static int i = 8; in the…
oz1cz
  • 5,504
  • 6
  • 38
  • 58
25
votes
3 answers

Inline function linkage

I can't make sense of the following behavior: one header with some basic types, and another header in which I use these types in several functions. Afterward I started constructing classes based on my defined types and functions. In the function…
Cristina
  • 1,991
  • 3
  • 17
  • 24
24
votes
1 answer

OVERRIDE_BY_INLINE in Kotlin

When implementing an interface in Kotlin with an inline function: interface Foo { fun qux(fn: () -> Unit) } open class Bar : Foo { final override inline fun qux(fn: () -> Unit){TODO()} } the IDE (and possibly the compiler) complains with…
SOFe
  • 7,867
  • 4
  • 33
  • 61
24
votes
1 answer

how to limit the queryset of an inline model in django admin

I have two models implemented like class A(models.Model): a_name = models.CharField(max_length=50) class B(models.Model): a = models.ForeignKey(A) b_tag = models.CharField(max_length=50) user=models.ForeignKey(User) #…
krishnan
  • 263
  • 1
  • 2
  • 7
24
votes
3 answers

Detect inline/block type of a DOM element

How to detect whether a DOM element is block or inline with javascript? For example, is there a function/property which returns 'inline' for a '' tag (or 'block' for a '

' tag)? Thank you.

abernier
  • 27,030
  • 20
  • 83
  • 114
24
votes
2 answers

What happens with an extern inline function?

What happens if I define the function in my .h file as extern int returnaint(void); define it in the related .c file as inline int returnaint(void) { return 1; } and include the header in another .c file and use the function? When I compile…
musicmatze
  • 4,124
  • 7
  • 33
  • 48
24
votes
6 answers

inline if statement java, why is not working

Desc: compareChar returns true or false. if true it sets the value of button, if false do nothing. I am trying to use: if compareChar(curChar, toChar("0")) ? getButtons().get(i).setText("§"); netbeans is saying: ')' excepted ':' excepted I…
Erik Kubica
  • 1,180
  • 3
  • 15
  • 39
23
votes
3 answers

small functions defined in header files: inline or static?

I have a number of small functions which are defined in a .h file. It is a small project (now) and I want to avoid the pain of having declarations and definitions separate, because they change all the time. To avoid multiply-defined symbols, I can…
eudoxos
  • 18,545
  • 10
  • 61
  • 110
23
votes
4 answers

Can modern C++ compilers inline functions that are defined in a cpp file

I am aware that the keyword inline has useful properties e.g. for keeping template specializations inside a header file. On the other hand I have often read that inline is almost useless as hint for the compiler to actually inline functions. Further…
Martin
  • 4,738
  • 4
  • 28
  • 57
23
votes
6 answers

decreasing cache misses through good design

How to decrease the number of possible cache misses when designing a C++ program? Does inlining functions help every time? or is it good only when the program is CPU-bounded (i.e. the program is computation oriented not I/O oriented)?
Josef
  • 353
  • 1
  • 2
  • 8
23
votes
1 answer

Does SASS support inline IF statements?

I'd like to set a SASS variable using inline IF's similar to how its done in PHP or Javascript Is something like this possible? $myVar: ($something >= 10 ? true : false); I'm aware of @if control directives but I want to use a shorter inline…
Nick Carson
  • 678
  • 1
  • 4
  • 11
23
votes
2 answers

How can I display two div in one line via css inline property

I try to use css inline property to make div node display in one line, below is my code
user2155362
  • 1,657
  • 5
  • 18
  • 30