FUNCTIONS

[1]  These are function "Prototypes".  They essentially allow functions to be defined ahead of time so the compiler can accommodate their use without having to compile the actual function code.  If prototypes were not used, the entire code would have to be compiled in the strict order in which the functions were called:  In this example, that would be tc2( ), tc1( ) and then main( ).

[2]  Main calling routine, not much else to say here!

[3]  This function returns a byte of output, but does not require any input data. The "STATIC" in the variable declaration ensures that variable will retain its value from one call to the next.  If it were specified as "STATIC CHAR tempxx = 0;" it would make no sense to be static as tempxx would always be set to 0 every time the function is called.

[4]  It is a good idea to  use an intermediary variable instead of modifying the calling one lest it modifies it in the scope of main( ) as well.
//[1]
CHAR tc2 (CHAR);
CHAR tc1 (VOID);

//[2]
VOID
main (VOID){
CHAR tempx;
CHAR tempy;
CHAR counter=0;
WHILE (TRUE){
  counter++;
  tempy=tc2(counter);
  tempx=tc1();
  tempy=tc1();
}

//[3]
CHAR tc1 (VOID){
STATIC CHAR tempxx;
CHAR temp;
tempxx++;
temp = tc2(tempxx);
return temp;
}

//[4]
CHAR tc2 (CHAR param){
param = param + 90;

RETURN param;
}
 

Any questions or comments?
 This page last updated on August 28, 2011