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

Can I check if the C# compiler inlined a method call?

I'm writing an XNA game where I do per-pixel collision checks. The loop which checks this does so by shifting an int and bitwise ORing and is generally difficult to read and understand. I would like to add private methods such as private bool…
Ben S
  • 68,394
  • 30
  • 171
  • 212
29
votes
7 answers

How do I require an inline in the Django Admin?

I have the following admin setup so that I can add/edit a user and their profile at the same time. class ProfileInline(admin.StackedInline): """ Allows profile to be added when creating user """ model = Profile class…
user147862
28
votes
3 answers

Can GHC really never inline map, scanl, foldr, etc.?

I've noticed the GHC manual says "for a self-recursive function, the loop breaker can only be the function itself, so an INLINE pragma is always ignored." Doesn't this say every application of common recursive functional constructs like map, zip,…
Jeff Burdges
  • 4,204
  • 23
  • 46
28
votes
3 answers

inline in definition and declaration

During a recent peer review, another Software Engineer suggested that I state that the inline function is inline in the definition (outside of the class) as well as in the declaration (inside of the class). His argument is that "By marking it…
user195488
28
votes
3 answers

friend AND inline method, what's the point ?

I see in a header that I didn't write myself the following: class MonitorObjectString: public MonitorObject { // some other declarations friend inline bool operator==(MonitorObjectString& lhs, MonitorObjectString& rhs) {…
Barth
  • 15,135
  • 20
  • 70
  • 105
28
votes
4 answers

inline function vs macro function

Possible Duplicate: Inline functions vs Preprocessor macros I want to know the difference between the inline function and macro function. 1) is inline function is the same of macro function ? 2) I know that both are not called but they are…
MOHAMED
  • 41,599
  • 58
  • 163
  • 268
27
votes
5 answers

List comprehension for loops Python

I use a lot of N dimensional arrays and it gets a pain to have to write such indented code and I know some codes can be replaced with list comprehensions and inline statements. For example: for x in (0,1,2,3): for y in (0,1,2,3): if x <…
disruptive
  • 5,687
  • 15
  • 71
  • 135
27
votes
1 answer

GHC not optimizing modules other than the main module

I'm currently writing a multi-module program in Haskell. I've found a strange problem where my files aren't being optimized properly, even though I'm passing in -O2 and so on. The files in question are shared 3D vector maths modules. When compiled…
Tom Hammersley
  • 279
  • 2
  • 8
27
votes
8 answers

Definition list with inline pairs

I'm trying to create a definition list of term-definition pairs, each pair existing on a single, separate line. I've tried making dts and dds display:inline, but then I lose the line breaks between the pairs. How do I make sure I have a line for…
krainert
  • 375
  • 1
  • 4
  • 13
27
votes
1 answer

MethodImplOptions.AggressiveInlining vs TargetedPatchingOptOut

What is the difference between the MethodImplAttribute with the option MethodImplOptions.AggressiveInlining and the TargetedPatchingOptOut? When I searched on Google everybody seems to says that both (might) inline the method but without giving the…
Yann Lebel
  • 675
  • 1
  • 7
  • 17
27
votes
2 answers

Inline function "undefined symbols" error

I want to write an inline function, but I get an error. How can I fix it? Error information: Undefined symbols for architecture i386: "_XYInRect", referenced from: -[BeginAnimation ccTouchesEnded:withEvent:] in BeginAnimation.o ld: symbol(s)…
user1297301
  • 887
  • 1
  • 9
  • 12
26
votes
18 answers

React - Create nested components with loops

I have a little issue with React. I can't create a nested component with a for loop. What I want to do is create 9 cells of a table and then create 3 rows with 3 cells for every row and after that mount the 3 rows together and create a board…
neboduus
  • 418
  • 1
  • 5
  • 14
26
votes
3 answers

Vertical align not working on inline-block

I was told that: Vertical align only works for inline,inline-blocks,images,and table elements. It has to be applied on the child element, as oppose to the parent element, unlike text-align. However, when I tried to set vertical align middle on…
frosty
  • 2,559
  • 8
  • 37
  • 73
26
votes
6 answers

multiple definition of inline function

I have gone through some posts related to this topic but was not able to sort out my doubt completely. This might be a very naive question. I have a header file inline.h and two translation units main.cpp and tran.cpp. Details of code are as…
K71993
  • 261
  • 1
  • 3
  • 3
26
votes
3 answers

inline virtual function

In C++, my understanding is that virtual function can be inlined, but generally, the hint to inline is ignored. It seems that inline virtual functions do not make too much sense. Is that right? Can anybody give a case in which an inline virtual…
skydoor
  • 25,218
  • 52
  • 147
  • 201