Thursday, 1 September 2022

What is the distinction between a procedure and a function when, in the object code functions are called procedurally?

My understanding is that for compiled languages such as C++, the compiler substitutes the line where the functions are called for the statements in the function body.

Why then, is there a difference between functions and procedures ? Since, a procedure is changing state in-line and so are functions, once compiled ?

pseudocode:

main()
{
let a = 1;
a = add_one(a);
}

fn add_one(n) {
  n + 1
}

at compile time, something like... (apologies, attempting to write pseudocode from my memory of that assembly class ~10 years ago is hard)

ASSIGN 1 to A
ASSIGN A FN ADDONE A
FN ADDONE A // Essentially, the function is converted into a procedure
A + 1 // That is evaluated and substituted in-line
EXIT


from What is the distinction between a procedure and a function when, in the object code functions are called procedurally?

No comments:

Post a Comment