OBNC – Frequently asked questions (FAQ)


Input problems on macOS

Question

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?

Answer

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, OBCN 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

CFLAGS="-include SDL/SDL.h"

This will make the C preprocessor include SDL.h when myprog.c is compiled.


Installation on MS Windows

Question

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?

Answer

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 installd 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:

  1. Create the directory C:\Program Files (x86)\obnc

  2. Extract obnc_a.b.c_win32.zip in the obnc directory

  3. Add C:\Program Files (x86)\obnc\obnc-a.b.c to the PATH environment variable.

Installation of OBNC-libext:

  1. Create the directory C:\Program Files (x86)\obnc\obnc-lib

  2. Extract obnc-libext_x.y.z.tar.gz and copy the ext directory to the obnc-lib directory

  3. 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.


Scope of local identifiers

Question

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

Answer

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.


Membership test for sets

Question

For a set s and an integer x which is not in the set universe, x IN s may evaluate to TRUE. How come?

Answer

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