printf("hello world\n");
(if the input box is not empty, clear everything with CTRL-L before) and select OK. For some units, this will already complete the creation of the instance. In many cases, including our example, a second dialog box will appear, querying you further parameters (the parameters for the first dialog are creation parameters that cannot be changed later without remaking the instance from scratch; the parameters in the second dialog affect only properties that can be dynamically modified during the lifetime of the instance without causing its re-creation from scratch). For the present example, just accept the suggested defaults with OK. As a result, a little icon labelled prog_unit appears in the circuit window. This is the just created, new instance. Make a few more instances of the prog_unit by repeating the entire procedure. Note that each new attempt will provide you with dialog boxes filled with your previous input as a suggested default. Use CTRL-L to clear an input field entirely, or edit it suitably (e.g., create a few prog_units that print different text lines).
printf("i=%d\n",i++);
If you then select OK (try it), this will destroy the current instance and replace it by an instance for the new specification (if you select CANCEL, the old specification will become restored and the unit remains unchanged). You also will have to fill in or accept the entries for the second dialog box in this case. When you now execute the newly created instance several times, you will see the outputs
i=0
i=1
i=2
...
i.e., the prog_unit (as most other units) preserves its state information (in this case the value of the variable i) between invocations (note also that the prog_unit does not force you to declare any (scalar) variables; undeclared variables are by default assumed to be of type float). You now can try out the difference between modifying run-time parameters and creation parameters: If you just change the label of the instance (run-time parameter, select '#' for accessing the second dialog window), executing the instance after the change will continue with the previous state, e.g.
i=3
i=4
...
If, however, you change something to the program text (creation parameter, select 'm' for the first dialog), even if it is only the addition of a comment:
printf("i=%d\n",i++); // a comment
subsequent execution will show that the value of the variable has been reset to 0, since the instance has been completely remade.
#import "file"
To avoid name collisions, you can also restrict the import, e.g., to the subset of functions starting with "f" and the single function "rewind" by the syntax
#import "file.f*"
#import "file.rewind"
The next example consists of a prog_unit that demonstrates the use of #import directive, together with some file-io function calls (note that in the prog_unit file pointers are implemented simply as float values, with 0 for "no file", so again, no declarations are necessary). An important use of the #import directive is the import C-functions from self-written shared libraries. This requires only the addition of a few lines of wrapper code to the implementation of your library, for a detailed explanation consult chapter Importing library objects and the prog_unit manual page.