### What happens exactly when you invoke a function....

• What exactly is a function definition (in any programming language)

• Consider the following function definition:

 ``` float f(float x) { return x*x; } ```

• The function definition defines the following black box:

Specifically:

• The parameter definition:

 ``` float f(float x) { return x*x; } ```

means:

 The function will use the float encoding (= IEEE 754) to encode the values of the variable x (see: click here )

• The return type:

 ``` float f(float x) { return x*x; } ```

means:

 The function will return a value is encoded using the float encoding (= IEEE 754)

• Another example:

 ``` int g(float a) { return a*a; } ```

means:

 The function g( ) will use the float encoding (= IEEE 754) to encode the values of the variable a The function will return a value is encoded using the float encoding (= IEEE 754)

• Extremely important fact

• Extremely important fact:

• Computer uses different codes to represent different types of values

Example:

 ``` int x = 2 Binary number (code) in x = 00000000000000000000000000000010 int x = -2 Binary number (code) in x = 11111111111111111111111111111110 float x = 2; Binary number (code) in x = 01000000000000000000000000000000 It's a IEEE &54 code: 0 10000000 00000000000000000000000 float x = -2; Binary number (code) in x = 11000000000000000000000000000000 It's a IEEE &54 code: 1 10000000 00000000000000000000000 ```

• Example Program: (Demo above code)

How to run the program:

 Right click on link(s) and save in a scratch directory To compile:   gcc data-repr.c To run:          a.out

• What happens when you call a function

• Consider the following function call to float f(float x):

 ``` float f(float x) { return x*x; } int main( int argc, char* argv[ ]) { .... b = f(a); } ```

• Important fact:

• The compiler must make sure that:

 ``` b = f( a ); ```

the value of a is encoding using float (IEEE 754)

• The compiler must also make sure that:

 ``` b = f( a ); ```

the return value of f( ) is converted to the data type of the variable b !!!