Agreed. This is not a bug.
This reminds me of the "case" statement in Pascal 6000 (CDC). If you wanted to prevent a crash of your program, when an expression (variant-selector) was not matched by any case-constant-list, you HAD TO include an empty "otherwise" clause. BTW, when I reported this behaviour (ie. crash) as a bug, I was told that since a non-match was undefined, it was acceptable for the program to terminate with a run-time error (which is what it normally did).
Joe.
-----Original Message----- From: CBFalconer [SMTP:cbfalconer@yahoo.com] Sent: Friday, November 01, 2002 2:35 AM To: gpc@gnu.de Subject: Re: BUG? empty else
Eike Lange wrote:
The following program compiles without warnings:
{ 2.1 (20020510), based on gcc-2.95.2 19991024 (release) } program bug;
var i: Integer = 1;
begin if i = 1 then WriteLn ('is 1') else if i = 2 then { do nothing } else { do nothing } end.
Not a bug. Terrible program structure, leading to much confusion, but valid. The null statement is specifically permitted. You will often see such things as:
WHILE whatever DO (* nothing *);
With if/else if/else chains, a useful rule is to put the short clauses first (if possible) and make the final else the longest clause. i.e.:
IF something THEN BEGIN (* lots of code *) END ELSE BEGIN (* a few lines *) END;
is inferior to:
IF NOT something THEN BEGIN (* a few lines *) END ELSE BEGIN (* lots of code *) END;
for readability reasons. You can look up from any code and find the controlling statement easily. This applies to most languages. The compiler should normally be able to optimize away any extra code generated.
-- Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net) Available for consulting/temporary embedded and systems. http://cbfalconer.home.att.net USE worldnet address!
"da Silva, Joe" wrote:
Agreed. This is not a bug.
This reminds me of the "case" statement in Pascal 6000 (CDC). If you wanted to prevent a crash of your program, when an expression (variant-selector) was not matched by any case-constant-list, you HAD TO include an empty "otherwise" clause. BTW, when I reported this behaviour (ie. crash) as a bug, I was told that since a non-match was undefined, it was acceptable for the program to terminate with a run-time error (which is what it normally did).
Once again, this is not a bug. I believe there is still no otherwise clause specified for ISO 7185 (it certainly wasn't for the original standard, which lead to heated debate). If you didn't specify each possible case you had made a programming error.