# ExecuteAsSubroutine

Executes previously loaded code as a subroutine.

### Synopsis

`int32 ExecuteAsSubroutine(CodeHandle code,int32 argc, char **argv);`

### Description

This function lets you execute a chunk of code that was previously loaded from disk using `LoadCode()`. The code will run as a subroutine of the current task or thread.

In order to function correctly, code being run as a subroutine should be linked with subroutinestartup.o instead of the usual cstartup.o.

The argc and argv parameters are passed directly to the `main()` entry point of the loaded code. The return value of this function is the value returned by `main()` of the code being run.

The values you supply for argc and argv are irrelevant to this function. They are simply passed through to the loaded code. Therefore, their meaning must be agreed upon by the caller of this function, and by the loaded code.

### Arguments

code
  A code handle filled in by a previous call to LoadCode().

argc
  A value that is passed directly as the argc parameter to the loaded code's main() entry point. This function doesn't use the value of this argument, it is simply passed through to the loaded code.

argv
  A value that is passed directly as the argv parameter to the loaded code's main() entry point. This function doesn't use the value of this argument, it is simply passed through to the loaded code.

### Return Value

Returns the value that the loaded code's `main()` function returns.

### Implementation

Folio call implemented in file folio V21.

### Caveats

If code being executed as a subroutine calls `exit()`, the parent thread or task will exit, not just the subroutine code.

### Associated Files

filefunctions.h

### See Also

``LoadCode`(), UnloadCode(), ExecuteAsThread()`