Difference between revisions of "Function"

From Chilipedia
Jump to: navigation, search
(See Also)
Line 11: Line 11:
 
== What's really goin on here tho ==
 
== What's really goin on here tho ==
 
What actually happens when a function is called is: the values to be passed to the function are placed somewhere where the function code can access them (called the stack, or in some calling conventions the parameters are put into CPU registers), then the current execution address is saved and the CPU jumps to the function address and begins executing the function instructions. At the end of the function, the result (if any) is placed in a predetermined location (typically a register), and the CPU jumps back to the address that it had previously saved and continues on its merry way.
 
What actually happens when a function is called is: the values to be passed to the function are placed somewhere where the function code can access them (called the stack, or in some calling conventions the parameters are put into CPU registers), then the current execution address is saved and the CPU jumps to the function address and begins executing the function instructions. At the end of the function, the result (if any) is placed in a predetermined location (typically a register), and the CPU jumps back to the address that it had previously saved and continues on its merry way.
 +
 +
== Tutorial Videos ==
 +
[[Beginner C++ Game Programming Tutorial 1]]
  
 
== See Also ==
 
== See Also ==
 
http://www.cplusplus.com/doc/tutorial/functions/
 
http://www.cplusplus.com/doc/tutorial/functions/

Revision as of 13:30, 1 August 2016

A function is a grouping of code that you can invoke or 'call' from one or more points in your program. You can even call a function from itself (motherfucking funception)!

Function Calls

A function call in C++ generally looks something like this obj.MyFunction( param1,param2 ). It consists of the function name (Myfunction in the example above) followed parentheses () which surround parameters separated by commas (,). To call a member function of an object, you first type the object name, then a period '.', and then the function name (e.g. obj.).

The function parameters are used to control the behavior of the function. A function can have zero or more of these. A function can also return a value, which can be used in other operations. If a function does not return a value, its return type is void.

Declaring and Defining Functions

Cumming soon ;)

What's really goin on here tho

What actually happens when a function is called is: the values to be passed to the function are placed somewhere where the function code can access them (called the stack, or in some calling conventions the parameters are put into CPU registers), then the current execution address is saved and the CPU jumps to the function address and begins executing the function instructions. At the end of the function, the result (if any) is placed in a predetermined location (typically a register), and the CPU jumps back to the address that it had previously saved and continues on its merry way.

Tutorial Videos

Beginner C++ Game Programming Tutorial 1

See Also

http://www.cplusplus.com/doc/tutorial/functions/