# _CP_load

_CP_load is an optional function for
preloading BASIC subroutines, before they are needed.

## Syntax

```
int _CP_load(int* number, CPSTR* name)
```

## Parameter(s)

| number | Must be a pointer to an integer. This integer must contain -1 when loading a new subroutine. Upon successful load, this location will contain an index number which should be passed down to succeeding _CP_calls to the same subroutine. This index allows the system to jump directly into the subroutine code without having to look up the name in the master dictionary. |
| --- | --- |
| name | Should be a CPSTR* pointing to the subroutine name. The subroutine to be called must be previously compiled with FlashBASIC and be cataloged in the current master dictionary. This function returns -1 if an error occurs. The error code is contained in _CP_errno, including:PE_LOAD_ERR which indicates that the system could not load the subroutine. The subroutine must be cataloged, and must be compiled with the current version of FlashBASIC. |
Note: All subroutines called *must* have been previously
compiled with the current version of FlashBASIC.

## Example(s)

```
/* call a user-written routine */

CPSTR * s = _CP_mkstr("hi");
int i = -1;

r = _CP_load(&i,s);
if (r < 0)
{
_CP_logoff();
exit(-1);
}
/* Now that the subroutine is loaded, it can be called */
/* very efficiently */

for (j=1; j < 100; j++) _CP_call(&i,s,0);
```

## See also

- [C functions overview](https://d3codex.com/cfunctions/c-functions-overview/)

---
Source: https://d3codex.com/cfunctions/cp-load/ - part of the D3Codex reference.
