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
23
votes
2 answers

Do I need to bother with INLINE/INLINABLE pragmas for small, exported, functions, or will GHC do it for me?

I have a module which collects and exports a bunch of small functions such as: fromEither :: (MonadError e m) => Either e a -> m a fromEither = either throwError return or withError :: MonadError e m => (e -> e) -> m a -> m a withError = flip…
Petr
  • 62,528
  • 13
  • 153
  • 317
23
votes
4 answers

Is there a standard for embedding JSON in HTML?

I would like to embed JSON in HTML. The most elegant solution I have found makes use of the script-tag and the mime media type application/json. Is this the…
T. Junghans
  • 11,385
  • 7
  • 52
  • 75
23
votes
2 answers

Should I define static inline methods in header file?

I've read about how it is usually best not to define anything in header files because redundant copies are made for every other file that includes the header file. However, in the case of static inline methods, it appears that I have to define it on…
Some Newbie
  • 1,059
  • 3
  • 14
  • 33
22
votes
1 answer

Error with inline and Xcode 4.2.1

I'm trying to get the inline package working on my macbook. The following block of code (from the cxxfunction examples) fails: library(inline) fx <- cxxfunction( signature(x = "integer", y = "numeric" ) , ' return ScalarReal( INTEGER(x)[0] *…
Zach
  • 29,791
  • 35
  • 142
  • 201
22
votes
3 answers

Customize `::-webkit-scrollbar` inline with React

How can I apply the ::-webkit-scrollbar pseudo elements to a component using inline styling in React?
galah92
  • 3,621
  • 2
  • 29
  • 55
22
votes
2 answers

Are static variables inlined by default inside templates in C++17?

Are static variables inlined by default inside templates in C++17? Here's an example: template struct SomeClass { static T test; }; struct SomeClass2 { static constexpr int test = 9; }; Are those variables inlined or still need…
Guillaume Racicot
  • 39,621
  • 9
  • 77
  • 141
22
votes
3 answers

How do I know if a function has been inlined or not?

If I mark any function as inline, is there a way I can know if the function gets inlined or not?
Rakesh Agarwal
  • 3,009
  • 9
  • 33
  • 40
22
votes
5 answers

Force a function to be inline in Clang/LLVM

Is there a way to force an inline function in Clang/LLVM? AFAIK, the following is just a hint to the compiler but it can ignore the request. __attribute__((always_inline)) I don’t mind that the compilation will fail if it can’t inline the function.
DavidS
  • 2,160
  • 1
  • 19
  • 22
22
votes
4 answers

What is the difference between anonymous and inline functions in JavaScript?

The title sums up my question. An example that demonstrates the point would be nice.
matori82
  • 3,669
  • 9
  • 42
  • 64
22
votes
1 answer

Twitter-Bootstrap - put simple elements inline

Is there anyway to put 2 elements displaying inline? i tryed : and also but it doesn't work.
itsme
  • 48,972
  • 96
  • 224
  • 345
21
votes
3 answers

Must the definition of a C++ inline functions be in the same file?

I defined a function show() as inlined in a header file called ex.h and the definition of the function inside ex.cpp. I expected that this will give me an error since the compiler will not know what to replace where the show() function is called.…
AlexDan
  • 3,203
  • 7
  • 30
  • 46
21
votes
3 answers

Forward declaration of inline functions

I have a header file that is going to contain a large amount (30+) of inline functions. Rather than having the reader scroll or search for the definition (implementation) of the inline function, I would like to have a forward declaration section…
Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154
21
votes
2 answers

Inline object instantiation and transformation in Java

I have come to Java from Visual Basic, and seem to think I have been, in many ways, spoiled :p Is there a way to instantiate an object and modify it inline? Something like: JFrame aFrame = new JFrame(); aFrame.add(new JPanel() {.setSize(100,100)…
GCon
  • 1,397
  • 3
  • 16
  • 33
21
votes
2 answers

R: C++ Optimization flag when using the inline package

In R when using the cxxfunction from the inline package, how does one change the optimization flag for the cpp compiler? By default, on my machine, it compiles with -g -O2. But I would like to use the -O3 optimization to gain speed. I use the Rcpp…
tlamadon
  • 970
  • 9
  • 18
21
votes
5 answers

Accessing this from within an object's inline function

I'm having difficulty referencing "this" from within a javascript inline function, within an object method. var testObject = { oThis : this, testVariable : "somestring", init : function(){ console.log(this.testVariable); //…
Matt
  • 1,140
  • 2
  • 10
  • 17