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
130
votes
1 answer

When should inline be used in Rust?

Rust has an "inline" attribute that can be used in one of those three flavors: #[inline] #[inline(always)] #[inline(never)] When should they be used? In the Rust reference, we see an inline attributes section saying The compiler automatically…
WiSaGaN
  • 46,887
  • 10
  • 54
  • 88
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,837
  • 3
  • 35
  • 50
124
votes
4 answers

How to execute Python inline from a bash shell

Is there a Python argument to execute code from the shell without starting up an interactive interpreter or reading from a file? Something similar to: perl -e 'print "Hi"'
Sean
  • 1,487
  • 3
  • 10
  • 9
118
votes
3 answers

Is "inline" without "static" or "extern" ever useful in C99?

When I try to build this code inline void f() {} int main() { f(); } using the command line gcc -std=c99 -o a a.c I get a linker error (undefined reference to f). The error vanishes if I use static inline or extern inline instead of just…
Sven Marnach
  • 574,206
  • 118
  • 941
  • 841
111
votes
5 answers

how to create inline style with :before and :after

I generated a bubble chat thingy from http://www.ilikepixels.co.uk/drop/bubbler/ In my page I put a number inside of it .bubble { position: relative; width: 20px; height: 15px; padding: 0; background: #FFF; border: 1px solid #000; …
Nick Ginanto
  • 31,090
  • 47
  • 134
  • 244
109
votes
10 answers

Java - Check Not Null/Empty else assign default value

I am trying to simplify the following code. The basic steps that the code should carry out are as follows: Assign String a default value Run a method If the method returns a null/empty string leave the String as default If the method returns a…
Cam1989
  • 1,241
  • 2
  • 9
  • 9
106
votes
8 answers

Function declaration inside or outside the class

I am a JAVA developer who is trying to learn C++, but I don't really know what the best practice is for standard function declarations. In the class: class Clazz { public: void Fun1() { //do something } } Or outside: class…
JohnJohnGa
  • 15,446
  • 19
  • 62
  • 87
102
votes
5 answers

Should one never use static inline function?

There are two implications of using the inline keyword(§ 7.1.3/4): It hints the compiler that substitution of function body at the point of call is preferable over the usual function call mechanism. Even if the inline substitution is omitted, the…
Alok Save
  • 202,538
  • 53
  • 430
  • 533
98
votes
7 answers

How can I erase all inline styles with javascript and leave only the styles specified in the css style sheet?

If I have the following in my html:
And this in my css style sheet: div { width:100px; height:100px; background-color:#000000; } Is there any way, with…
Matt
  • 5,547
  • 23
  • 82
  • 121
90
votes
2 answers

Is there still a use for inline?

I believed, inline was obsolete because I read here: No matter how you designate a function as inline, it is a request that the compiler is allowed to ignore: the compiler might inline-expand some, all, or none of the places where you call a…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
88
votes
11 answers

Is it good practice to make getters and setters inline?

public: inline int GetValue() const { return m_nValue; } inline void SetValue(int nNewValue) { this -> m_nValue = nNewValue; } On Learn C++, they said it would run faster. So, I thought it would be great to…
Martijn Courteaux
  • 67,591
  • 47
  • 198
  • 287
87
votes
10 answers

Limit foreign key choices in select in an inline form in admin

The logic is of the model is: A Building has many Rooms A Room may be inside another Room (a closet, for instance--ForeignKey on 'self') A Room can only be inside another Room in the same building (this is the tricky part) Here's the code I…
mightyhal
  • 1,667
  • 1
  • 14
  • 8
84
votes
5 answers

C++ inline member function in .cpp file

I know that inline member functions by definition should go into the header. But what if it's not possible to put the implementation of the function into the header? Let's take this situation: File A.h #pragma once #include "B.h" class A{ B…
Mat
  • 2,713
  • 5
  • 25
  • 25
82
votes
6 answers

What is the use of the `inline` keyword in C?

I read several questions in stackoverflow about inline in C but still am not clear about it. static inline void f(void) {} has no practical difference with static void f(void) {}. inline void f(void) {} in C doesn't work as the C++ way. How does it…
user3810155
81
votes
6 answers

When should I make a function inline?

Why should I do something like this: inline double square (double x) { return x * x; } instead of double square (double x) { return x * x; } Is there a difference?
Pwnna
  • 9,178
  • 21
  • 65
  • 91