gawk: Calling Built-in
1
1 9.1.1 Calling Built-in Functions
1 --------------------------------
1
1 To call one of 'awk''s built-in functions, write the name of the
1 function followed by arguments in parentheses. For example, 'atan2(y +
1 z, 1)' is a call to the function 'atan2()' and has two arguments.
1
1 Whitespace is ignored between the built-in function name and the
1 opening parenthesis, but nonetheless it is good practice to avoid using
1 whitespace there. User-defined functions do not permit whitespace in
1 this way, and it is easier to avoid mistakes by following a simple
1 convention that always works--no whitespace after a function name.
1
1 Each built-in function accepts a certain number of arguments. In
1 some cases, arguments can be omitted. The defaults for omitted
1 arguments vary from function to function and are described under the
1 individual functions. In some 'awk' implementations, extra arguments
1 given to built-in functions are ignored. However, in 'gawk', it is a
1 fatal error to give extra arguments to a built-in function.
1
1 When a function is called, expressions that create the function's
1 actual parameters are evaluated completely before the call is performed.
1 For example, in the following code fragment:
1
1 i = 4
1 j = sqrt(i++)
1
1 the variable 'i' is incremented to the value five before 'sqrt()' is
1 called with a value of four for its actual parameter. The order of
1 evaluation of the expressions used for the function's parameters is
1 undefined. Thus, avoid writing programs that assume that parameters are
1 evaluated from left to right or from right to left. For example:
1
1 i = 5
1 j = atan2(++i, i *= 2)
1
1 If the order of evaluation is left to right, then 'i' first becomes
1 six, and then 12, and 'atan2()' is called with the two arguments six and
1 12. But if the order of evaluation is right to left, 'i' first becomes
1 10, then 11, and 'atan2()' is called with the two arguments 11 and 10.
1