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_M.N.P_win32.zip
for 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
. Assuming OBNC is to be installed in this directory, follow the steps below (and replace M.N.P
with the actual version).
Create the directory C:\Program Files (x86)\obnc
Extract obnc_M.N.P_win32.zip
in the obnc
directory
Add C:\Program Files (x86)\obnc\obnc-M.N.P
to the PATH environment variable (press Win+S and search for "Edit environment variables for your account"). This step is needed to make Windows find the OBNC commands when you type them in a command prompt.
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