Jump to content
Excelsior Forums
Sign in to follow this  
AlexIljin

Enumeration problem

Recommended Posts

XDS 2.51, default configuration, Windows platform.

I'm trying to use an enumeration type FORMAT declared in a definition module (Definition.def) in my Oberon module (Project.ob2). The enumeration initially comes from a C header file, and I needed to create a special constant = "-1" belonging to the type. I did it the way I saw it done in the Windows.def:

CONST FIF_UNDEFINED = SYSTEM.CAST (FORMAT, 0FFFFFFFFh);

When I try to compile the following assignment:

VAR fmt: Definition.FORMAT;
BEGIN fmt := Definition.FIF_UNDEFINED;

the compiler detects an error: E122 expression out of bounds.

Here are the files to reproduce the problem with some additional comments:

make.bat, makeDef.prj, makePrj.prj - needed to compile

Definition.def, Project.ob2 - sources

File contents:

:: make Definition.sym

xc.exe =p =a makeDef.prj

:: make Project.ob2

xc.exe =p makePrj.prj

-makefile-

!module Definition

!module Project

<* ENUMSIZE="4" *><* +M2EXTENSIONS *>

DEFINITION MODULE ['StdCall'] Definition;

IMPORT SYSTEM;

TYPE

  FORMAT = (

    FIF_BMP,

    FIF_ICO

  );

CONST

  FIF_UNKNOWN = SYSTEM.CAST (FORMAT, 0FFFFFFFFh);

END Definition.

(* Why is the assignment below impossible, although the comparison works? *)

<* +MAIN *><* -GUI *><* +NOOPTIMIZE *>(* NOOPTIMIZE is to avoid IF elimination, not necessary *)

MODULE Project;

IMPORT Definition,Out,SYSTEM;

VAR fmt: Definition.FORMAT;

BEGIN

   (* The SYSTEM.VAL version works as expected. *)

   fmt := SYSTEM.VAL (Definition.FORMAT, Definition.FIF_UNKNOWN);

   (* But the following line would not compile (E122 expression out of bounds) *)

   fmt := Definition.FIF_UNKNOWN;

   (* The comparison below is compiled without any complaints. *)

   IF fmt = Definition.FIF_UNKNOWN THEN

      Out.String ('Constant check 1: OK.');

      Out.Ln;

   ELSE

      Out.String ('Constant check 1: FAILED.');

      Out.Ln;

   END;

END Project.

Command to compile: make.bat

Is this a compiler bug?

Is there anything I can do to make it work without using the SYSTEM.VAL?

Will the SYSTEM.VAL always work as expected, or are there any side-effects possible?

Share this post


Link to post
Share on other sites

Sorry I can't help, I didn't even know that enumerations could be anything other than CARDINAL (or at least non-negative) type.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×