-
Notifications
You must be signed in to change notification settings - Fork 14
Running and debugging
To run PicoC scripts one should begin by transferring plain-text C source files, with .c extension, to the calculator. If you prefer a more tedious alternative, you can also write a C program using the editor in Utilities and then saving the file with extension .c.
These files can be executed by opening the Utilities file manager, then opening the details screen for the C source file, and pressing F4 or EXE, ou simply by pressing EXE twice from the file listing. If pressing EXE opens the file as text instead, this means you have the wrong edition of Utilities - the one without PicoC support.
PicoC in Utilities does not offer any kind of debugging facilities. Like with native add-in development, your best bet is to stick to drawing stuff on the screen to indicate your program status as it runs.
However, PicoC does syntax checking, and if it runs into a run-time error, like undefined symbols, it will stop and complain about it, indicating the error and the line number where the error occurred.
Full terminal emulation isn't supported, which means you won't be able to use the standard library functions for getting input and returning output - just like what happens with Prizm add-ins. However, for convenience, output may be displayed after the script finishes running, or once an error occurs.
Display of output is not guaranteed, for technical reasons to do with the memory used to store it. Output is guaranteed to be displayed correctly if, and only if:
- The calculator does not go into standby during the execution of the script (i.e. Shift+AC/On is pressed, or the power-off timeout expires);
- The output doesn't exceed 4096 bytes (output past this size will be dropped);
- The system or the script doesn't modify IL Memory contents during the execution of the script.
For example, if one tries to use a undefined symbol, the following is shown:
In this case, the error is in file scr1.c, line 4.
If a script writes to the terminal (for example, using printf), when the program finishes running the following will be shown:
The "code" is the exit code of the program, which is 0 by default, and corresponds to the parameter of the exit
function. So to exit with code 1234, one could do exit(1234);
.
This screen with the exit code and output is only shown if there's any output to display (subject to the conditions above), or if the exit code is not zero.