SPC Version 0.9.5
Code order has two aspects: the order in which the code appears in the source code file and the order in which it is executed at runtime.
The first will be referred to as the lexical order and the second as the runtime order.
The lexical order is important to the SPC compiler, but not to the SuperPro brick. This means that the order in which you write your task and function definitions has no effect on the runtime order. The rules controlling runtime order are:
This last rule may seem trivial, but it has important consequences when multiple tasks are running. If a task calls a function that is already in the midst of running because it was called first by another task, unpredictable behavior and results may ensue. Tasks can share functions by treating them as shared resources and using code to prevent one task from calling the function while another task is using it.
The rules for lexical ordering are:
Sometimes you will run into situations where is impossible or inconvenient to order the task and function definitions so the compiler knows every task or function name before it sees that name used in a code block. You can work around this by inserting task or function declarations of the form
before the code block where the first usage occurs. The
argument_list must match the list of formal arguments given later in the function's actual definition.