Forum > Operating Systems

Inconsistency between Windows and Linux compiling?

<< < (3/5) > >>

Laksen:
It's probably libraries of the host system that are overriding the exception mask, as Bart suggests. If it's a big problem then include the math unit, and in the start of the program do SetExceptionMask([]);

Alex Kidd:

--- Quote from: Laksen on June 12, 2011, 11:53:48 am ---It's probably libraries of the host system that are overriding the exception mask, as Bart suggests. If it's a big problem then include the math unit, and in the start of the program do SetExceptionMask([]);

--- End quote ---

I tried the SetExceptionMask suggestion and it works  ;D

Thank you so much to all users who kindly answered my question.

Lazarus is a fantastic project and I think it's gonna replace very soon Java, Mono and Python for my cross-platform needs (especially the GUI related). I just need to experiment some more.

In the meanwhile I'm spreading the voice with my colleagues, showing the capabilities of Lazarus. A couple of Delphi nostalgic didn't even know there was an open source project going on and now are thanking me for the hint!

Zoran:
What is actually this ExceptionMask?
I can't find anything in documentation. %)
And I think that this diferrent behavior is not a minor thing, I realy would like to understand what it is about.

Laksen:
The exception mask is the mask for exceptions coming from the FPU :)

So if it's entirely unmasked(as is the default for FreePascal) all exceptional behaviour will generate an exception. However if it's masked, either entirely or partly(as is the default for some C programs), the operation will go unnoticed: 1/0 will become +Inf, log(0) will be NaN, etc

The FreePascal RTL does clear this exception mask when the program starts, but if the program subsequently loads DLLs or SOs that override the exception mask for the process then the program won't be notified. And it can go the other way too. Some C DLL/SOs might "randomly" generate exceptions because they might rely on unsafe FPU operations :)

Zoran:

--- Quote from: Laksen on June 12, 2011, 11:53:48 am ---It's probably libraries of the host system that are overriding the exception mask, as Bart suggests.

--- End quote ---
If I understand correctly, this means that if some library is called by the application and that library changes this exception mask for its own purposes, than the whole program will change its exception handling?! :o


--- Quote from: Laksen on June 12, 2011, 11:53:48 am ---If it's a big problem then include the math unit, and in the start of the program do SetExceptionMask([]);

--- End quote ---

Does not work. Setting the ExceptionMask to empty set in program start creates many new exceptions and the application crashes.

There are problems even if the ExceptionMask is set for this simple isolated line:

--- Code: ---procedure TForm1.Button1Click(Sender: TObject);
var
  X, Y: Integer;
  Res: Double;
  FPUExceptionMask: TFPUExceptionMask;
begin
  X := StrToInt(Edit1.Text);
  Y := StrToInt(Edit2.Text);
  try
    FPUExceptionMask := SetExceptionMask([]);
    try
      Res := X / Y; // I set ExceptionMask only for this line of code
    finally
     SetExceptionMask(FPUExceptionMask); // and restore it back
    end;

    Label3.Caption := FloatToStr(Res);
  except
    on E: Exception do
      Label3.Caption := E.ClassName + ' - ' + E.Message;
  end;

end;

--- End code ---
Now it raises EInvalidOp, when I use non-divisible integers, although the result is regularly stored in Double, something which works well if I do not mess with ExceptionMask (see the picture).

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version