[fpc-pascal] else and otherwise in a case statement

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Thu Dec 11 22:07:52 CET 2014


I've been doing a bulk replace of 'case..else' to 'case..otherwise' to 
eliminate possible ambiguities that have bitten me in the past, and have 
noticed something interesting under 2.6.4 on x86 Linux.

This is OK:

         Ord('.'): case shiftState of
                     unshifted: mechCode := Corr_88_Period;
                     shifted:
                   else
                   end;

This is an error:

         Ord('.'): case shiftState of
                     unshifted: mechCode := Corr_88_Period;
                     shifted:
                   otherwise
                   end;

I can fix it like this:

         Ord('.'): case shiftState of
                     unshifted: mechCode := Corr_88_Period;
                     shifted: ;
                   otherwise
                   end;

But that grates since I was brought up on ; being a statement separator 
rather than a terminator. Alternatively this is OK:

         Ord('.'): case shiftState of
                     unshifted: mechCode := Corr_88_Period;
                     shifted:
                   end;

but I like having the regular code (in some cases there are active 
otherwise clauses, and I spent enough time with Modula-2 to prefer 
enumerating all possibilities).

Is this difference expected, and what is the best workaround?

-- 
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]



More information about the fpc-pascal mailing list