[fpc-devel] Minor debate with ISO standard on case blocks

Martin Frb lazarus at mfriebe.de
Tue Jul 30 11:21:39 CEST 2019


On 30/07/2019 10:29, Michael Van Canneyt wrote:
>
>
> On Tue, 30 Jul 2019, thaddy wrote:
>
>> Telling.
>>>
>>> NOTES
>>>
>>> 1. If it is possible to construct a program in which the violation or
>>> non-violation of this International Standard requires knowledge of the
>>> data read by the program or the implementation definition of
>>> implementation-defined features, then violation of that requirement is
>>> classified as an error. Processors may report on such violations of
>>> the requirement without such knowledge, but there always remain some
>>> cases that require execution, simulated execution, or proof procedures
>>> with the required knowledge. Requirements that can be verified without
>>> such knowledge are not classified as errors.
>
> Hm.
>
> Even after reading this 5 times, I still am not sure I understand the
> above. The people who wrote this must have been either extraordinary 
> geniuses, or very confused minds.
>
> Or else they wanted to give a befriended unemployed lawyer some work.
> But anyone writing such a paragraph deserves to be unemployed... ;)
>
> How you're suppsed to construct a working & compliant 'processor' (I 
> assume this means compiler or interpreter or somesuch) after reading 
> this is a mystery to me.

Well if we make the following substitutions (to specialize the statement 
for the case of fpc)

processor = compiler
error = run time error

Then the firsts sentence:
     "If it is possible to construct a program
     in which the violation (*or non-violation*) of this International 
Standard
     requires knowledge of the data read by the program
     (*   or the implementation definition of implementation-defined 
features,  *)
     then violation of that requirement is classified as an error. "

Says: if reading the source does not show if the data will be correct, 
then none correct data shall be a run time error

     "Compiler may report on such violations of
     the requirement without such knowledge"

"such knowlededge" = knowing the data read
If the compiler can say the data will not be correct, then it may report 
at compile time.

    " but there always remain some cases
      that require execution, simulated execution, or proof procedures
      with the required knowledge."

Not all cases can be (reasonable) detected at compile time

      " Requirements that can be verified without
       such knowledge are not classified as errors. "

(probably?): violations detected at compile time, are not (run time?) 
errors.

--------------------------------------------------------------
So if the standard did say, that all values in the defined range of the 
type of the variable (or result type of the expression in the case) must 
have an entry in the case list, then the compiler is allowed to bail out 
during compilation.

But:
"On execution of the case-statement the case-index shall be evaluated. 
That value shall then specify execution of the statement of the 
case-list-element closest-containing thecase-constant denoting that 
value. One of the case-constants shall be equal to the value of the 
case-index upon entry to the case-statement; otherwise, it shall be an 
error."

Only says, that the values that actually occur at runtime, must be 
present. It does not say that the range of the type must be fully present.

if boolval <> false then
   case boolval of
      true: ;
   end;

Is therefore valid. Even though the case has no entry for false.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190730/4d03e37f/attachment.html>


More information about the fpc-devel mailing list