Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. What is Inline declaration?
Forum Updated to NodeBB v4.3 + New Features

What is Inline declaration?

Scheduled Pinned Locked Moved Solved C++ Gurus
5 Posts 4 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Swati777999S Offline
    Swati777999S Offline
    Swati777999
    wrote on last edited by
    #1

    Hi All,

    I am following the book C++ GUI Programming with Qt.

    In chapter 4, section -subclassing QTable Widget , I came across a statement,

    The autoRecalculate() function is implemented inline since it just returns whether or not auto-recalculation is in force.

    What is meant by implemented inline ?

    From this site : webeduclick.com

    "An inline function is a function that is expanded in line when it is invoked, the compiler replaces the function call with the corresponding function code."

    What's the specialty of inline function? Aren't all functions replaced by their logic in their call statement?

    Please clarify doubt!

    Thanks!

    “ In order to be irreplaceable, one must always be different” – Coco Chanel

    J.HilkJ 1 Reply Last reply
    1
    • Swati777999S Swati777999

      Hi All,

      I am following the book C++ GUI Programming with Qt.

      In chapter 4, section -subclassing QTable Widget , I came across a statement,

      The autoRecalculate() function is implemented inline since it just returns whether or not auto-recalculation is in force.

      What is meant by implemented inline ?

      From this site : webeduclick.com

      "An inline function is a function that is expanded in line when it is invoked, the compiler replaces the function call with the corresponding function code."

      What's the specialty of inline function? Aren't all functions replaced by their logic in their call statement?

      Please clarify doubt!

      Thanks!

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #4

      @Swati777999 to expand a little bit on what the others wrote.

      calling functions is not free, its very cheap, but its not free.

      Generally speaking, when calling a function a couple of operations have to be done, before the actual instructions of your function are started to be executed.

      • Preparing parameters for the function
      • Preparing the return value of the function
      • Prologue and epilogue code, local memory management, parameter memory management and register value preservation, jumping to the different memory address where your function instruction is stored, etc
      • clearing of already cached instructions

      All this "takes time", relatively speaking.

      by inlining you remove that overhead and trade speed for size.

      Keep in mind, that in c++ the inline keyword is a suggestion from you to your compiler, the compiler may very well ignore it or do inlining by itself

      for more information:
      https://en.cppreference.com/w/cpp/language/inline


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      Swati777999S 1 Reply Last reply
      4
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote on last edited by
        #2

        It is as written. "inline" explicitly tells the compiler to replce the call statement with the function/method body where it is called. in tight iterative loops this can increase performance over the normal subroutine call when not inlined. As a generality get/set operations are good to inline since they are often simple assignments, so are shorter than the the indirect subroutine call just to then do the assignment.

        1 Reply Last reply
        4
        • JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by
          #3

          inline function avoids overhead of function call because wherever inline function is called is replaced by the content of inline function in compiling time.
          Your compiled code with inline functions is faster, but has bigger size.

          1 Reply Last reply
          1
          • Swati777999S Swati777999

            Hi All,

            I am following the book C++ GUI Programming with Qt.

            In chapter 4, section -subclassing QTable Widget , I came across a statement,

            The autoRecalculate() function is implemented inline since it just returns whether or not auto-recalculation is in force.

            What is meant by implemented inline ?

            From this site : webeduclick.com

            "An inline function is a function that is expanded in line when it is invoked, the compiler replaces the function call with the corresponding function code."

            What's the specialty of inline function? Aren't all functions replaced by their logic in their call statement?

            Please clarify doubt!

            Thanks!

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #4

            @Swati777999 to expand a little bit on what the others wrote.

            calling functions is not free, its very cheap, but its not free.

            Generally speaking, when calling a function a couple of operations have to be done, before the actual instructions of your function are started to be executed.

            • Preparing parameters for the function
            • Preparing the return value of the function
            • Prologue and epilogue code, local memory management, parameter memory management and register value preservation, jumping to the different memory address where your function instruction is stored, etc
            • clearing of already cached instructions

            All this "takes time", relatively speaking.

            by inlining you remove that overhead and trade speed for size.

            Keep in mind, that in c++ the inline keyword is a suggestion from you to your compiler, the compiler may very well ignore it or do inlining by itself

            for more information:
            https://en.cppreference.com/w/cpp/language/inline


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            Swati777999S 1 Reply Last reply
            4
            • J.HilkJ J.Hilk

              @Swati777999 to expand a little bit on what the others wrote.

              calling functions is not free, its very cheap, but its not free.

              Generally speaking, when calling a function a couple of operations have to be done, before the actual instructions of your function are started to be executed.

              • Preparing parameters for the function
              • Preparing the return value of the function
              • Prologue and epilogue code, local memory management, parameter memory management and register value preservation, jumping to the different memory address where your function instruction is stored, etc
              • clearing of already cached instructions

              All this "takes time", relatively speaking.

              by inlining you remove that overhead and trade speed for size.

              Keep in mind, that in c++ the inline keyword is a suggestion from you to your compiler, the compiler may very well ignore it or do inlining by itself

              for more information:
              https://en.cppreference.com/w/cpp/language/inline

              Swati777999S Offline
              Swati777999S Offline
              Swati777999
              wrote on last edited by
              #5

              @J-Hilk said in What is Inline declaration?:

              for more information:
              https://en.cppreference.com/w/cpp/language/inline

              This link has better examples. Thanks for sharing!

              “ In order to be irreplaceable, one must always be different” – Coco Chanel

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved