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

Why is it not cost effective to inline functions with loops or switch statements?

I noticed that Google's C++ style guide cautions against inlining functions with loops or switch statements: Another useful rule of thumb: it's typically not cost effective to inline functions with loops or switch statements (unless, in the …
olliezhu
  • 752
  • 1
  • 8
  • 17
19
votes
4 answers

Does F# have generic arithmetic support?

Does F# have the same problem as C# where you can't directly use arithmetic operators with generic T types? Can you write a generic Sum function that would return the sum of any value that supports the arithmetic addition?
Joan Venge
  • 315,713
  • 212
  • 479
  • 689
19
votes
2 answers

Does it make sense to declare inline functions noexcept?

From what I can tell, the SO community is divided on whether declaring a function noexcept enables meaningful compiler optimizations that would not otherwise be possible. (I'm talking specifically about compiler optimizations, not library…
KnowItAllWannabe
  • 12,972
  • 8
  • 50
  • 91
19
votes
7 answers

Remove all inline styles using BeautifulSoup

I'm doing some HTML cleaning with BeautifulSoup. Noob to both Python & BeautifulSoup. I've got tags being removed correctly as follows, based on an answer I found elsewhere on Stackoverflow: [s.extract() for s in soup('script')] But how to remove…
Ila
  • 3,528
  • 8
  • 48
  • 76
19
votes
2 answers

What's the advantage of NS_INLINE over static inline?

Looking at the define of NS_INLINE it seems that the advantage of using it over static inline is compiler compatibility, is that correct? Should NS_INLINE always be used instead of static inline on c functions in objective-c projects? #if…
keegan3d
  • 10,357
  • 9
  • 53
  • 77
18
votes
2 answers

Why do inline functions have external linkage by default?

The standard says that given a declaration of inline void foo(); that foo is an inline function with external linkage (because by default all function declarations have external linkage). This strikes me as odd. because the one definition rule…
Billy ONeal
  • 104,103
  • 58
  • 317
  • 552
18
votes
2 answers

How exactly does V8 optimize/inline?

I'm wondering whether it is possible to get knowledge of how exactly V8 optimizes and inlines things. I created three simple test functions which all calculate the sine of a angle in degrees. I put them all into closures so that V8 should be able to…
pimvdb
  • 151,816
  • 78
  • 307
  • 352
18
votes
2 answers

How deep do compilers inline functions?

Say I have some functions, each of about two simple lines of code, and they call each other like this: A calls B calls C calls D ... calls K. (So basically it's a long series of short function calls.) How deep will compilers usually go in the call…
Paul Manta
  • 30,618
  • 31
  • 128
  • 208
18
votes
5 answers

Why are inline constructors and destructors not a good idea in C++?

I remember reading in one of the C++ books (quite some time ago) that it is not a good idea to have inline Constructors and Destructors especially for derived class. I understand that inlining would induce some bloating up of object code but are…
Nikhil Nehriya
  • 341
  • 1
  • 2
  • 13
18
votes
2 answers

Perl: how can I put all my inline C code into a separate file?

This problem is so simple I can feel the RTFM's coming. However, I've been looking at the docs (Inline, Inline-C, Inline-C-Cookbook ) all morning and I can't figure out how to solve this problem. I want to use inline C, but I don't want to have C…
flies
  • 2,017
  • 2
  • 24
  • 37
18
votes
5 answers

non-integral constants

I want a header file with a non-integral constant in it, e.g. a class. Note the constant does not need to be a compile-time constant. static const std::string Ten = "10"; This compiles but is undesirable as each compilation unit now has its own…
deft_code
  • 57,255
  • 29
  • 141
  • 224
18
votes
3 answers

How to add breakpoints in your inline javascript in chrome

I want to debug my javascript code and able to successfully place breakpoints at required places under sources tab. However, I have run into an issue where I want to debug my inline javascript code. Do we have any chrome debugging tool feature…
Sachin Jain
  • 21,353
  • 33
  • 103
  • 168
18
votes
3 answers
18
votes
6 answers

Is Java guaranteed to inline string constants if they can be determined at compile time

Consider this case: public Class1 { public static final String ONE = "ABC"; public static final String TWO = "DEF"; } public Class2 { public void someMethod() { System.out.println(Class1.ONE + Class1.TWO); } } Typically you would…
Yishai
  • 90,445
  • 31
  • 189
  • 263
18
votes
3 answers

Behavior of __LINE__ in inline functions

I have a macro that passes the line number and file name to an error handler: #define SYSTEM_FAILURE (error_code, comment) \ System_Failure((error_code), (comment), __LINE__, __FILE__); How will the __LINE__ be resolved when used inside an…
Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154