Difference between revisions of "Subroutine"

From SEGGER Wiki
Jump to: navigation, search
(Created page with "A subroutine is a piece of program code that is designed to be called by a program. It is not a stand-alone application, so it is not usable in itself. I an real world applica...")
 
m
Line 13: Line 13:
 
</syntaxhighlight>
 
</syntaxhighlight>
   
  +
===How does it work in practice===
  +
TBD
   
 
===Inlining===
 
===Inlining===
   
  +
==FAQs==
 
===What is the difference between a function and a subroutine?===
 
===What is the difference between a function and a subroutine?===
  +
The simple answer is: It is the same.
  +
Some people will disagree to that, saying that a function operates on local values (the parameters) only,
  +
that a function has to return a value. That would mean every function is a subroutine, but not every subroutine is a function.
  +
In any case, let's just assume they are the same and it is not worth arguing about.

Revision as of 10:02, 23 June 2019

A subroutine is a piece of program code that is designed to be called by a program. It is not a stand-alone application, so it is not usable in itself. I an real world application, the bulk of the program consists of subroutines. A subroutine can take parameters and return a value.

Let's look at a simple example of a subroutine:

int Max(int a, int b)
  if (a > b) {
    return a;
  }
  return b;
}

How does it work in practice

TBD

Inlining

FAQs

What is the difference between a function and a subroutine?

The simple answer is: It is the same. Some people will disagree to that, saying that a function operates on local values (the parameters) only, that a function has to return a value. That would mean every function is a subroutine, but not every subroutine is a function. In any case, let's just assume they are the same and it is not worth arguing about.