When using the basic module Input or XYplane on macOS, why is keyboard and mouse input not working correctly? How do I solve the problem?
The implementation of Input and XYplane uses the C library SDL. On macOS the header file SDL.h
must be included in the file where the function main is defined, that is in the C file which corresponds to the entry point Oberon module. When an Oberon module which imports Input or XYplane is compiled, OBNC is not aware of the SDL library since it is abstracted away by the imported modules. Therefor, OBNC cannot add the required SDL include directive in the generated C code.
There is, however, a workaround for the problem which uses the C preprocessor option -include
. This option is supported by the C compilers GCC and Clang. For the entry point module myprog
, create the file myprog.env
with the content
This will make the C preprocessor include SDL.h
when myprog.c
is compiled.
I have downloaded the compiler obnc_a.b.c_win32.zip
and the extended library obnc-libext_x.y.z.tar.gz
on MS Windows. How do I proceed?
OBNC can be installed in any directory. However, the recommended directory for a global installation is C:\Program Files (x86)\obnc
. To extract the content of the compressed files you need a program which can handle both .zip
and .tar.gz
files, like for instance the file archiver 7-Zip which is free software. Assuming that OBNC is to be installed in C:\Program Files (x86)
, follow the steps below (and replace a.b.c
and x.y.z
with the actual version numbers).
Installation of OBNC:
Create the directory C:\Program Files (x86)\obnc
Extract obnc_a.b.c_win32.zip
in the obnc
directory
Add C:\Program Files (x86)\obnc\obnc-a.b.c
to the PATH environment variable.
Installation of OBNC-libext:
Create the directory C:\Program Files (x86)\obnc\obnc-lib
Extract obnc-libext_x.y.z.tar.gz
and copy the ext
directory to the obnc-lib
directory
Add C:\Program Files (x86)\obnc\obnc-lib
to the environment variable OBNC_IMPORT_PATH.
After the installations, the directory structure should look like this:
C:\Program Files (x86)\obnc\ obnc-a.b.c\ obnc-lib\ ext\
It may also be a good idea to keep the compressed packages in the obnc
directory in case you need to reinstall one of the packages.
Why do I get the error message “undeclared identifier: x” in the following procedure?
PROCEDURE P; VAR x: INTEGER; PROCEDURE Q; BEGIN x := 1 END Q; END P
In later versions of Oberon, only two scopes are accessible inside a procedure: the global scope and the strictly local scope. Since the variable x is declared in an intermediate scope, it is inaccessible inside the procedure Q. The solution is to instead pass x to Q through a variable parameter.
For a set s and an integer x which is not in the set universe, x IN s may evaluate to TRUE. How come?
The value of the expression x IN s is undefined if x is negative, or if x is greater than the maximum element a set can hold (which is typically 31 or 63). Therefor, the program must make sure that x is within the correct bounds before the IN operator is used.
If the program needs to know the maximum element a set can hold, the following algorithm can be used:
PROCEDURE ElementMax(): INTEGER; VAR x: INTEGER; s: SET; BEGIN x := -1; s := -{}; REPEAT INC(x); EXCL(s, x) UNTIL s = {} RETURN x END ElementMax