Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2023-06

What is -CO ?

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mattias Gaertner

Hi,

What is -CO?

In the docs I can only find this sentence:
"Check for possible overflow of integer operations"

Mattias

Michalis Kamburelis
to Mattias Gaertner

I'm also curious :)

I just tested, and the -Co (lowercase "o") enables overflow checking by default (like "{$Q+}" in code),
https://github.com/michaliskambi/modern-pascal-introduction/wiki/What-are-range-and-overflow-checks-(and-errors)-in-Pascal .

But -CO (uppercase "O") seems unrelated to it.

This example:

"""
{$mode objfpc}
uses SysUtils;
var
  A: Int64;
begin
  A := High(Int64) - 100;
  A := A + 200;
  Writeln('Result is ', A);
end.
"""

... behaves the same, regardless if it's compiled with "-CO" or not. (Only "-Co" is relevant, controls do we make overflow check, as expected.)

Regards,
Michalis

pt., 9 cze 2023 o 12:03 Mattias Gaertner via fpc-pascal napisał(a):

Show quoted text 13 lines
Hi, What is -CO? In the docs I can only find this sentence: "Check for possible overflow of integer operations" Mattias _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Martin
to Mattias Gaertner: What is -CO? In the docs I can only find this sentence: "Check for possible overflow of…
Mattias Gaertner wrote 7 lines
Hi, What is -CO? In the docs I can only find this sentence: "Check for possible overflow of integer operations"

Done some testing. -CO produces the below warning.

program Project1;
var a,b: Integer;
var c: integer;
begin
a := Random(9999);
b := Random(9999);
c := a +b;  // project1.lpr(7,3) Warning: Type size mismatch, possible
loss of data / range check error
writeln(c);
end.

However it overdoes it.

make it
   var a,b: shortInt;

Then the ":=random" will warn => ok.
But the addition still warns, yet it can't ever fail. (even if the compiler internally uses int64)

Mattias Gaertner
to Jonas Maebe
Show quoted text 9 lines
On 09/06/2023 12:03, Mattias Gaertner via fpc-pascal wrote: > What is -CO? > > In the docs I can only find this sentence: > "Check for possible overflow of integer operations" It prints a warning whenever the compiler inserts an implicit type conversion to a type that cannot represent every value of the source type.

Thanks!

Maybe this can be added to the docs?

Mattias