[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.programming.threads

Read again about my objection about C++ and C

Ramine

12/30/2015 9:40:00 PM

Hello....


I have just took a look to operator overloading in FreePascal and
Delphi, so look at how powerful it is, here is an example:

===

program OperatorsTest;

{$APPTYPE CONSOLE}

uses
SysUtils;

type
TIntValue = record
private
FValue: Integer;
public
class operator Add(const a, b: TIntValue): TIntValue;
class operator Implicit(const a: Integer): TIntValue;
class operator Implicit(const a: TIntValue): Integer;
property Value: Integer read FValue;
end;

{ TIntValue }

class operator TIntValue.Add(const a, b: TIntValue): TIntValue;
begin
Result.FValue := a.FValue + b.FValue;
end;

class operator TIntValue.Implicit(const a: Integer): TIntValue;
begin
Result.FValue := a;
end;

class operator TIntValue.Implicit(const a: TIntValue): Integer;
begin
Result := a.FValue;
end;

var
Int: TIntValue;

begin
Int := 5;
Int := Int + 10;
WriteLn(IntToStr(Int));

end.
===



You can overload the following operators in both FreePascal and Delphi,
read here:

http://docwiki.embarcadero.com/RADStudio/Seattle/en/Operator_Ov...(Delphi)

In ADA when you define two types like this:

type length is new float;
type weight is new float;

You can not assign type length to type weight, this strong typing
of Ada you can do it easily with object oriented programming in
FreePascal and Delphi and C++.

So what remains about C and C++ is that in C++ and C you can
not at runtime catch the exception of signed int or unsigned int
overflow or underflow , this is a weakness in C++ and C , but
in FreePascal and Delphi you can easily do it by compiling
with the FreePasal compiler option -Co, after that you can catch the
exception named EIntOverflow like this:

try

except
on EIntOverflow do HandleIntOverflow;
end;


And the HandleIntOverflow you can reraise the exception by
returning the name of the function that raised this exception
of the signed or unsigned int overflow or underflow so that to catch the
bugs easily and that's good in realtime safety critical systems, so C++
and C can not do that and this is not suitable for realtime safety
critical system.


Thank you,
Amine Moulay Ramdane.