Chapter Contents

Previous

Next
isnotconst isnumconst isstrconst

Implementation of Functions


Built-in Functions and Macros

Many of the functions in the library are implemented as built-in functions. A built-in function is a function for which the compiler generates the required machine instructions directly in the compiled code instead of making a call to a separately compiled routine. True functions are compiled separately and must be linked with the program before they can be executed. By eliminating the overhead of parameter list creation and branching, a built-in function is always more efficient than a call to a true function. Generally, built-in functions can be implemented by a relatively short sequence of machine instructions. These afford the greatest increase in efficiency. The abs function is a good example:

#include <math.h>
int gt5(register int i){
 return (i < -5) ? i + 5 : abs(i);
 }

Given this C function, the compiler generates a single IBM 370 machine instruction called Load Positive Register (LPR) to get the absolute value of i . However, calling and executing the true abs function in this example requires the execution of 20 machine instructions.

The compiler and library implement built-in functions by defining a macro in the header file that prefixes the string _ _builtin_ to the function name. For example, the strcpy function is declared as follows:

#define strcpy(x, y) _ _builtin_strcpy(x, y)

The compiler recognizes the prefix and generates the appropriate machine instructions. If you do not include the header file, the compiler does not recognize the function as a built-in function and generates a call for the function.

For some built-in functions, the compiler may generate a call to the true function as part of the code sequence. This occurs when the value of one or more of the function arguments cannot be determined at compile time and may fall outside of the range of values that the in-line code can handle. At execution time, the arguments are evaluated, and either the in-line code is executed or the true function is called.

If a built-in function is called with invalid arguments or an invalid number of arguments, a call to the true function is generated. Following is a list of all SAS/C built-in functions:

_bbwd _stfregs llmax modf
_bfwd _stpregs llmin putc
_branch _stregs max sigchk
_cc abs memcmp strcmp
_cms202 ceil memcmpp strcpy
_code fabs memcpy strlen
_diag floor memcpyp strncmp
_label fmax memscan strscan
_ldexp fmin memscntb strscntb
_ldregs getc memset strxlt
_osarmvc labs memxlt tolower
_ossvc llabs min toupper

Following is a list of all SAS/C functions implemented as macros, other than built-in functions:

ABEND* TPUT_ASID* ffixed+ offsetof*
CHAP* TPUT_USERID* fnm+ onjmp*
CMSSTOR_OBT*+ TTIMER* fterm+ onjmpout*
CMSSTOR_REL*+ WAIT1* getchar palloc
DEQ* WAITM* htonl pause
DETACH* WAITT* htons pdset*
DMSFREE* WRTERM* isalnum pdval*
DMSFREE_V* WTP* isalpha pfree
DMSFRET* appcconn*+ iscics putchar
ENQ* appcrecv*+ iscntrl setbuf
ESTAE* appcscfd*+ iscsym shvdrop*
ESTAE_CANCEL* appcscnf*+ iscsymf shvfetch*
FREEMAIN* appcsdta*+ isdigit shvfirst*
GETLONG* appcserr*+ isebcdic shvnext*
GETMAIN_C* appcsevr*+ isgraph shvset*
GETMAIN_V* appcsreq*+ islower sigsetjmp*
GETMAIN_U* assert* isnotconst* strcspn
GETSHORT* atof isnumconst* strspn
POST* atoi isprint toebcdic
PUTLONG* cfgetispeed ispunct typlin*
PUTSHORT* cfgetospeed isspace unloadd
RDTERM* cmspush* isstrconst* va_arg*
STATUS* cmsqueue* isunresolved* va_end
STIMER* difftime isupper va_start*
STIMERM_CANCEL*+ e_SVC202 isxdigit waitrd*+
STIMERM_SET* execdrop* labs xedpoint
STIMERM_TEST* execfetch* localtime xedread
SVC202 execset* memchr xedstate
TGET* exit ntohl xedwrite
TPUT* fattr+ ntohs
* may not be undefined.

+ evaluates some arguments more than once.


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.