Function Calls

Functions are called by name with their arguments in parenthesis. Parenthesis are required even if the function being called takes no arguments. Unlike variables, functions are always global in scope and can be referenced from before their definition in the source text.

When you call a function you must take care that you supply it with the correct number and type of parameters, or you will see a compiler error.

Example 8.2. Function Call Examples

func1();
int y = add(func2(), 17);
increment();

Any arguments passed to a function call are passed by value. This means that the function has its own copy of any data you send to it, and so cannot affect any variables you might have passed. Note that in the case of object types you are passing a reference to the object, and so the function being called will be able to alter the object referenced.

Example 8.3. Call-by-value Example

// This function advances a recordset a number of rows
void jump_rows(Recordset rs, int numrows)
{
    while(!rs.eof() && numrows > 0)
    {
        rs.next();
        numrows--;
    }
}

int num = 42;
Recordset rs = conn.openrs("SELECT * FROM mytable");

jump_rows(rs, num);

After the call to jump_rows() the variable num still equals 42 because jump_rows() was given a copy of it to work with. The recordset referred to by rs has been advanced 42 rows.