[fpc-devel] Dangerous optimization in CASE..OF
Ondrej Pokorny
lazarus at kluug.net
Sun Jul 16 21:08:48 CEST 2017
On 16.07.2017 20:42, Florian Klämpfl wrote:
> "Ungültiger Maschinenbefehl (Speicherabzug geschrieben)" = Invalid
> opcode (memory dump written).
> Why? Because it does not range check before entering the jump table.
OK, I confess I am not a C guy (I hated it in the university even more
than fortran). But for me:
default-ondrej at ondrej-linux:~/ctest$ cat test.c
#include <stdio.h>
typedef enum { e1,e2,e3,e4,e5,e6,e7,e8 } tenum;
int f(tenum e)
{
switch (e)
{
case e1:
printf("Hello 1 %d\n",e1);
return 1;
case e2:
return 354;
case e3:
return 351;
case e4:
return 315;
case e5:
return 35;
case e6:
printf("Hello asdf\n");
return 1;
case e7:
printf("Hello \n");
return 2;
case e8:
printf("Hello\n");
return 3;
default:
printf("default");
return 0;
}
}
int main()
{
f(12);
}
ondrej at ondrej-linux:~/ctest$ gcc test.c
ondrej at ondrej-linux:~/ctest$ ./a.out
defaultondrej at ondrej-linux:~/ctest$
No error if I remove the default statement.
Ondrej
More information about the fpc-devel
mailing list