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
79
votes
4 answers

Use of `inline` in F#

The inline keyword in F# seems to me to have a somewhat different purpose than what I'm used to in e.g. C. For example, it seems to affect a function's type (what are "statically resolved type parameters"? Aren't all F# types resolved…
J Cooper
  • 16,891
  • 12
  • 65
  • 110
79
votes
13 answers

Logo image and H1 heading on the same line

I want to create my first web page but I encountered a problem. I have the following code: logo

My website name

I'd like to know how to make the logo and the H1 to be in the same line. Thanks!
Six Quads
  • 815
  • 1
  • 6
  • 7
78
votes
3 answers

inline vs __inline vs __inline__ vs __forceinline?

What are the differences between these four inline (key)words? inline, __inline, __inline__, __forceinline.
Xavier Ho
  • 17,011
  • 9
  • 48
  • 52
76
votes
8 answers

How do I force gcc to inline a function?

Does __attribute__((always_inline)) force a function to be inlined by gcc?
HaltingState
  • 1,810
  • 1
  • 20
  • 22
70
votes
17 answers

Why main() in C++ cannot be inlined?

I was reading the C++ FAQs and I noticed one sentence. main() cannot be inline. Why is this?
jon
  • 615
  • 5
  • 4
69
votes
2 answers

undefined reference when calling inline function

I am getting a really odd error from GCC 4.8.1 with inline functions. I have two near-identical inline functions defined in header files (debug.h and error.h) in src/include/, with the only difference being what they print - one prefixes DEBUG: to…
Marco Scannadinari
  • 1,774
  • 2
  • 15
  • 24
63
votes
4 answers

How to check for null in a single statement in scala?

In my scala code: QueueManager.add(getObject) where getObject is a method that returns an object of type QueueObject. def getObject : QueuObject = { val response = //some response return response } Is there a way I can check for the…
theTuxRacer
  • 13,709
  • 7
  • 42
  • 59
62
votes
4 answers

How much faster is it to use inline/base64 images for a web site than just linking to the hard file?

How much faster is it to use a base64/line to display images than opposed to simply linking to the hard file on the server? url(data:image/png;base64,.......) I haven't been able to find any type of performance metrics on this. I have a few…
Tim
  • 671
  • 1
  • 7
  • 5
62
votes
10 answers

CSS two divs width 50% in one line with line break in file

I want to build a fluid layout using percentages for widths. Here is my HTML:
A
B
The problem is that the elements won't display together on one…
Chris
  • 1,068
  • 2
  • 12
  • 18
61
votes
4 answers

Loading an external font via inline CSS

Is it possible to load an external font via inline CSS? Note: I'm not talking about using an external CSS file with a @font-face definition, but rather something like the following:

Randomize
  • 8,651
  • 18
  • 78
  • 133

57
votes
11 answers

Why not mark everything inline?

First off, I am not looking for a way to force the compiler to inline the implementation of every function. To reduce the level of misguided answers make sure you understand what the inline keyword actually means. Here is good description, inline…
deft_code
  • 57,255
  • 29
  • 141
  • 224
56
votes
3 answers

C++ inlining class methods causes undefined reference

I'm getting a compiler error when I try to inline a method of one of my classes. It works when I take away the "inline" keyword. Here's a simplified example: main.cpp: #include "my_class.h" int main() { MyClass c; c.TestMethod(); return…
FrankMN
  • 825
  • 1
  • 10
  • 10
55
votes
5 answers

Why are pointers to inline functions allowed?

I have two questions: 1) Why are pointers to inline functions allowed in C++? I have read that the code of inline functions just gets copied to the function call statement and there is no compile-time memory allocation in inline functions. So why…
Madhuchhanda Mandal
  • 917
  • 1
  • 7
  • 20
54
votes
4 answers

How do define anonymous functions in C++?

Can I define functions in C++ inline? I am talking about lambda functions, not the inline keyword that causes a compiler optimization.
danijar
  • 32,406
  • 45
  • 166
  • 297
52
votes
1 answer

Can the linker inline functions?

In the file file1.c, there is a call to a function that is implemented in the file file2.c. When I link file1.o and file2.o into an executable, if the function in file2 is very small, will the linker automatically detect that the function is small…
Squall
  • 4,344
  • 7
  • 37
  • 46