6

Why is pascal giving me unreachable code in line (8,21) and (8,12). I don't know why its a simple code for making an octal number of 3 digits to decimal. The program is ok because is giving me the right result, but I don't know why free pascal is giving me the unreachable code in that section of the program.

I'm using 3.0.4 freepascal on Linux, I only use the command I posted to compile, I don't modify anything from freepascal I'm using the following command to compile fpc -Co -Cr -Miso -gl

PROGRAM Ejercicio21;
VAR decimal,octal,a,b,c:integer;
BEGIN
    writeln('Ingrese el valor decimal: ');
    readln(octal);
    a:=(octal div 100);
    b:=(octal mod 100) div 10;
    c:=octal mod 10;
    decimal:=(a*sqr(8)+(b*8)+c);
    writeln('Octal',octal,'=',decimal); 
END.
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
  • 3
    Compiler warnings tend to be specific to the compiler being used, so your q should say which compiler you are using. Which is it? Fwiw, I tried comiling your code using FreePascal and it compiled without any warnings, and it's not obvious why your compiler should emit those warnings, if they are referring to the line ` c:=octal mod 10;` – MartynA May 09 '20 at 09:31
  • 1
    There is nothing in the code you've posted that would be *unreachable*, which means that this probably isn't your actual code. *Unreachable code* always means that there's an `if` or `else` branch that will never be run, or code that exists after every possiblily before it results in a `return`. – Ken White May 09 '20 at 12:23
  • Hey, the compiler its freepascal, i don't know why its reachable code :/ – Thiago Montiel May 09 '20 at 20:02
  • 4
    I tried your code in an Ubuntu VM which has FPC 3.0 and Lazarus 1.6.2 installed and using the command line switches you quote, fpc -Co -Cr -Miso -gl. With those switches, I get 'Unreachable code' warnings for lines 8&9. Removing the -Miso switch avoids the warnings. I think you should report this behaviour at https://forum.lazarus.freepascal.org/ and ask whether it is expected. Btw, in view of the fact that I could reproduce this using the info in your edited q, I am voting to re-open it. – MartynA May 10 '20 at 09:44
  • In spite of the warnings, the code seems to execute as expected. – lurker May 10 '20 at 13:08
  • 1
    A minimal case of the issue: `program sample; var a:integer; begin a := 100; a := a mod 100; end.` The error is always on the `mod` operator. And you only need the `-Miso` option to produce it. – tonypdmtr May 10 '20 at 21:37
  • Ok, so it's just a bug?, sorry for all the problems I have produced :/ – Thiago Montiel May 10 '20 at 22:47
  • No need to apologize for that. Ultimately, the compiler produced the problem, not you. :) – lurker May 11 '20 at 02:27

2 Answers2

0

Just ignore the warning.

Really, the first line is all I wanted to say, but I got a warning from StackOverflow that my answer was too short. Ironic to get a warning when answering a question about a warning.

kd4ttc
  • 1,075
  • 1
  • 10
  • 28
0

Try

VAR octal :integer;
BEGIN
    writeln('Ingrese el valor decimal: ');
    readln(octal);
    writeln(octstr(octal),' = ',decimal);
end;
Marco van de Voort
  • 25,628
  • 5
  • 56
  • 89