CASE statement

Topics related to the use of Oberon language features
Locked
pic
Posts: 1
Joined: Tue Jul 05, 2011 8:45 pm

CASE statement

Post by pic » Sat Sep 24, 2011 11:38 am

Hi,

as noticed in Oberon07.Report.pdf: 'The case expression must be of type INTEGER, and all labels must be non-negative integers.'
ok, so far so good, but here is my code and problem:

Code: Select all

PROCEDURE SetOrientation( ort: INTEGER );

VAR
  lcdOrientation, lcdWidth, lcdHeight: INTEGER;
    
BEGIN
  CASE ort OF
    0:   lcdOrientation := 0;   lcdWidth := 320; lcdHeight := 240; WriteCmd( 016H, 0A8H )
    | 90:  lcdOrientation := 90;  lcdWidth := 240; lcdHeight := 320; WriteCmd( 016H, 008H )
    | 180: lcdOrientation := 180; lcdWidth := 320; lcdHeight := 240; WriteCmd( 016H, 068H )
    | 270: lcdOrientation := 270; lcdWidth := 240; lcdHeight := 320; WriteCmd( 016H, 0C8H )
  END

END SetOrientation;
The last case label is set to a value of 270, as u can see above. i get a compilation' error bad case label'.
When i use values below 256 everything compiles fine.

How can this be ?

Regards Michael

cfbsoftware
Site Admin
Posts: 493
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: CASE statement

Post by cfbsoftware » Sat Sep 24, 2011 1:21 pm

The maximum value that you can use as a label in a CASE statement in the Astrobe implementation of Oberon is 255.

Refer to the Implementation Limits section in the Astrobe documentation for more information.

If you really want to use a CASE statement you could rewrite your example as:

Code: Select all

  lcdOrientation := ort;
  CASE ort DIV 90 OF
      0: lcdWidth := 320; lcdHeight := 240; WriteCmd( 016H, 0A8H )
    | 1: lcdWidth := 240; lcdHeight := 320; WriteCmd( 016H, 008H )
    | 2: lcdWidth := 320; lcdHeight := 240; WriteCmd( 016H, 068H )
    | 3: lcdWidth := 240; lcdHeight := 320; WriteCmd( 016H, 0C8H )
  END
However using DIV with a divisor that is not a power of two is inefficient. Your particular example will be smaller and execute faster if you use a chain of IF-ELSIF-ELSIFs...

Locked