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
49
votes
10 answers

How will i know whether inline function is actually replaced at the place where it is called or not?

I know that inline function are either replaced where it is called or behave as a normal function. But how will I know whether inline function is actually replaced at the place where it is called or not as decision of treating inline function as…
Abhineet
  • 6,459
  • 10
  • 35
  • 53
48
votes
2 answers

How to disable a linting rule inline in flutter

Is there a way to disable a linting rule for a line in flutter? I have a specific use case where I want to disable linting for two lines. I have a lot of business logic already written so I cannot change the code. abstract class ReviewName { …
SRAVAN
  • 769
  • 1
  • 7
  • 11
48
votes
1 answer

Inline function cannot access non-public-API: @PublishedApi vs @Suppress vs @JvmSynthetic

In Kotlin, when I have a non-public member and an inline fun that calls it, there's a compilation error saying: Error:(22, 25) Kotlin: Public-API inline function cannot access non-public-API private fun f(): Unit defined in com.example I found…
hotkey
  • 140,743
  • 39
  • 371
  • 326
47
votes
1 answer

Is there any reason not to use the INLINABLE pragma for a function?

The documentation states: An {-# INLINABLE f #-} pragma on a function f has the following behaviour: While INLINE says "please inline me", the INLINABLE says "feel free to inline me; use your discretion". In other words the choice is left to GHC,…
glaebhoerl
  • 7,695
  • 3
  • 30
  • 41
46
votes
3 answers

inline vs. constexpr?

With the new C++11 standard, when should I use the inline keyword over the constexpr keyword? Does the constexpr keyword offer any additional optimization over inline, or does it merely assert that things must be computed at compile-time? Why does…
RétroX
  • 1,996
  • 4
  • 16
  • 24
45
votes
4 answers

Does constexpr imply noexcept?

Does constexpr specifier imply noexcept specifier for a function? Answer to the similar question says "yes" concerning inline specifier, but Eric Niebler's article makes me wonder about possible answer to the current one. On my mind answer can…
Tomilov Anatoliy
  • 15,657
  • 10
  • 64
  • 169
43
votes
4 answers

Is "inline" implicit in C++ member functions defined in class definition

According to the C++ specification, are the following two classes equivalently defined? class A { void f() { } }; class B { inline void f() { } }; i.e., is putting the "inline" qualifier on such member function defined in the…
Sam
  • 995
  • 2
  • 10
  • 19
43
votes
6 answers

F# collection initializer syntax

What is the collection initializer syntax in F#? In C# you can write something like: new Dictionary() { {"One", 1}, {"two", 2}} How do I do the same thing in F#? I suppose i could roll my own syntax, but seems like there should…
srparish
  • 1,708
  • 1
  • 16
  • 22
43
votes
16 answers

Why is inlining considered faster than a function call?

Now, I know it's because there's not the overhead of calling a function, but is the overhead of calling a function really that heavy (and worth the bloat of having it inlined) ? From what I can remember, when a function is called, say f(x,y), x and…
kodai
  • 3,080
  • 5
  • 32
  • 34
41
votes
3 answers

What's the c++ inline class?

I accidentally found that the Clang compiler allows : inline class AAA { }; in C++. What's this? PS. I reported this to Clang mailing list cfe-dev@cs.uiuc.edu, and now waiting for reply. I'll update this question by I'm informed.
eonil
  • 83,476
  • 81
  • 317
  • 516
40
votes
9 answers

Inline function v. Macro in C -- What's the Overhead (Memory/Speed)?

I searched Stack Overflow for the pros/cons of function-like macros v. inline functions. I found the following discussion: Pros and Cons of Different macro function / inline methods in C ...but it didn't answer my primary burning question. Namely,…
Jason R. Mick
  • 5,177
  • 4
  • 40
  • 69
40
votes
2 answers

When should I (and should I not) use Scala's @inline annotation?

I believe I understand the basics of inline functions: instead of a function call resulting in parameters being placed on the stack and an invoke operation occurring, the definition of the function is copied at compile time to where the invocation…
Graham Lea
  • 5,797
  • 3
  • 40
  • 55
40
votes
6 answers

C# sending mails with images inline using SmtpClient

SmtpClient() allows you to add attachments to your mails, but what if you wanna make an image appear when the mail opens, instead of attaching it? As I remember, it can be done with about 4 lines of code, but I don't remember how and I can't find it…
KdgDev
  • 14,299
  • 46
  • 120
  • 156
39
votes
5 answers

JavaScript: IIF like statement

Coming from VB, JavaScript isn't very easy to get the hang of. Please don't be negative, I've tried and searched loads but with no luck. BTW, I'm creating a dropdown control initialized from a Select option list in JS. Dummy code: var col =…
Alex Guerin
  • 2,336
  • 10
  • 36
  • 53
39
votes
5 answers

What does __inline__ mean ?

I am trying to learn C. Reading through some code, I came across a line like this: __inline__ void () ... What does the __inline__ mean?. How does putting that word in front of a function make it different?
ggg
  • 937
  • 5
  • 13
  • 16