Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Borland Delphi > BACK TO SCHOOL ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 3697 of 3852
Post > Topic >>

BACK TO SCHOOL YOU SONS OF *****ES, Lesson 1: Integer Basics.

by "Skybuck Flying" <BloodyShame@[EMAIL PROTECTED] > Apr 16, 2008 at 12:29 PM

Hello,

See comments, or see website for details.

http://members.home.nl/hbthouppermans/D2007Analysis/Index.htm

// *** Begin of AnalysisLesson1.dpr ***

program AnalysisLesson1;

{$APPTYPE CONSOLE}

{

(File extension .txt added for easy web browsing)

Version 0.01 created on 16 april 2008 by Skybuck Flying.

Lesson 1, Integer Basics

For me this is kinda boring because I am pretty good at Delphi...
but then again one never knows what one might encounter...

So just to be fair to visual studio 2008 and c/c++ I will now conduct
the same tests in Delphi 2007.

I am pretty good at tracking down bugs in Delphi... so for me it's not
that
much of an issue... but anyway if the compiler could find more integer 
related
bugs that might safe some time even for me ;) :)

And ofcourse this lesson might be interesting for newbs to delphi lol :)

So here ya go folks... Skybuck at it again. ;)

Slighty different types used: types have a T infront of it to prevent any 
name space conflicts.

GOOD THING I PERFORMED THIS TEST.

It seems somebody at Borland made another HUUUUUUGGGGGGEEE **** UP !

Now I can proudly and angryly say:

BACK TO SCHOOL YOU SONS OF *****ES.

I was gonna say: Perfection is the key... but no sir bob ! Delphi
definetly 
not perfect.

Conclusions:

Out of range detection for int8 ok.
Out of range detection for uint8 ok.

Out of range detection for int16 ok.
Out of range detection for uint16 ok.

Out of range detection for int32 ok.
Out of range detection for uint32 ok.

Out of range detection for int64 BAD.
Out of range detection for uint64 ok.

Legal range for int8 ok.
Legal range for uint8 ok.

Legal range for int16 ok.
Legal range for uint16 ok.

Legal range for int32 ok.
Legal range for uint32 ok.

Legal range for int64 SEMI-OK, SEMI-BAD.
Legal range for uint64 ok.

Out of range/Range detection is done at compile, errors are displayed in
the 
messages window.

Platform tested intel architecture 32.

14 out of 16 tests passed.
2 out of 16 tests failed.

Score:

8.75 out of 10.

(Still 1.25 points better than c/c++ :))

Debateable question raised:

Should out of range assignments be allowed when range checking is off ?

(Currently it's not allowed, thus it performs range checking even when
it's 
off, kinda funny)

}

uses
  SysUtils;

type
 Tint8 = shortint;
 Tuint8 = byte;

 Tint16 = smallint;
 Tuint16 = word;

 Tint32 = integer;
 Tuint32 = longword;

 Tint64 = int64;
// Tuint64 = int64; // uint64 is buggy, -1 point for delphi 2007.
 Tuint64 = uint64; // using buggy uint64 implementation for now just to
test 
ranges.

procedure Main;
var
 vMinInt8 : Tint8;
 vMaxInt8 : Tint8;

 vMinUint8 : Tuint8;
 vMaxUint8 : Tuint8;

 vMinInt16 : Tint16;
 vMaxInt16 : Tint16;

 vMinUint16 : Tuint16;
 vMaxUint16 : Tuint16;

 vMinInt32 : Tint32;
 vMaxInt32 : Tint32;

 vMinUint32 : Tuint32;
 vMaxUint32 : Tuint32;

 vMinInt64 : Tint64;
 vMaxInt64 : Tint64;

 vMinUint64 : Tuint64;
 vMaxUint64 : Tuint64;

begin

 writeln('Program Started');
 writeln;

 // even without range checking on it gives errors when out of range
values 
are used.
 // should it really do that if range checking is off ?
 // this is debatable :)
 // I like it though... the more errors the compilers catches the better,
 // as long as there are ways around it, to allow it.
 // For example typecasting allows a lot wish is very good.

 // test int8
 writeln('SizeOf(Tint8): ', SizeOf(Tint8) );

 vMinInt8 := -128; // -129 would give error: Constant expression violates 
subrange bounds. OK
 writeln('vMinInt8: ', vMinInt8 );

 vMaxInt8 := 127; // 128 would give error: Constant expression violates 
subrange bounds. OK
 writeln('vMaxInt8: ', vMaxInt8 );
 writeln;

 // test uint8
 writeln('SizeOf(Tuint8): ', SizeOf(Tuint8) );

 vMinUint8 := 0; // -1 would give error: Constant expression violates 
subrange bounds. OK
 writeln('vMinUint8: ', vMinUint8 );

 vMaxUint8 := 255; // 256 would give error: Constant expression violates 
subrange bounds. OK
 writeln('vMaxUint8: ', vMaxUint8 );
 writeln;

 // test int16
 writeln('SizeOf(Tint16): ', SizeOf(Tint16) );

 vMinInt16 := -32768; // -32769 would give error: Constant expression 
violates subrange bounds. OK
 writeln('vMinInt16: ', vMinInt16 );

 vMaxInt16 := 32767; // 32768 would give error: Constant expression
violates 
subrange bounds. OK
 writeln('vMaxInt16: ', vMaxInt16 );
 writeln;

 // test uint16
 writeln('SizeOf(Tuint16): ', SizeOf(Tuint16) );

 vMinUint16 := 0; // -1 would give error: Constant expression violates 
subrange bounds. OK
 writeln('vMinUint16: ', vMinUint16 );

 vMaxUint16 := 65535; // 65536 would give error: Constant expression 
violates subrange bounds. OK
 writeln('vMaxUint16: ', vMaxUint16 );
 writeln;

 // test int32
 writeln('SizeOf(Tint32): ', SizeOf(Tint32) );

 vMinInt32 := -2147483648; // -2147483649 would give error: Constant 
expression violates subrange bounds. OK
 writeln('vMinInt32: ', vMinInt32 );

 vMaxInt32 := 2147483647; // 2147483648 would give error: Constant 
expression violates subrange bounds. OK
 writeln('vMaxInt32: ', vMaxInt32 );
 writeln;

 // test uint32
 writeln('SizeOf(Tuint32): ', SizeOf(Tuint32) );

 vMinUint32 := 0; // -1 would give error: Constant expression violates 
subrange bounds. OK
 writeln('vMinUint32: ', vMinUint32 );

 vMaxUint32 := 4294967295; // 4294967296 would give error: Constant 
expression violates subrange bounds. OK
 writeln('vMaxUint32: ', vMaxUint32 );
 writeln;

 // test int64
 writeln('SizeOf(Tint64): ', SizeOf(Tint64) );

 // problem zone for maximum negative value and beyond:
 vMinInt64 := -9223372036854775808; // -9223372036854775809 would give 
error: Overflow in conversion or arithmetic operation (HMMM interesting 
inconsistency with the rest?!?).OK

 writeln('vMinInt64: ', vMinInt64 );

 // vMaxInt64 := 9223372036854775807; // should have been the real maximum
! 
tut tut tut !
 vMaxInt64 := 9223372036854775808; // 9223372036854775808 is allowed ?!?!?

FLAW !!! maximum range is supposed to be 9223372036854775808-1 ?!?!?!
WACKY 
investigate this further later on. Bunch of ****ing amateurs who coded
this 
range ?!?!?! PROBABLY BAD. DEFINETLY BAD !
           // would display -9223372036854775808 !!! DEFINETLY DEFINETLY
BAD 
RANGE ! FLAW IN DELPHI TUT TUT TUT
// vMaxInt64 := 9223372036854775809; // 9223372036854775809 would give 
error: Constant expression violates subrange bounds, doubtfull, probably 
wrong.
 writeln('vMaxInt64: ', vMaxInt64 );
 writeln;

 // test uint64
 writeln('SizeOf(Tuint32): ', SizeOf(Tuint64) );

 vMinUint64 := 0; // -1 would give error: Constant expression violates 
subrange bounds. OK
 writeln('vMinUint64: ', vMinUint64 );

 vMaxUint64 := 18446744073709551615; // 18446744073709551616 would give 
(different) error: Integer constant too large. OK
 writeln('vMaxUint64: ', vMaxUint64 );
 writeln;

 writeln('Program finished');
end;

begin
 try
  Main;
 except
  on E:Exception do
   Writeln(E.Classname, ': ', E.Message);
 end;
 readln;
end.

// *** End of AnalysisLesson1.dpr ***

Bye,
  Skybuck.
 




 1 Posts in Topic:
BACK TO SCHOOL YOU SONS OF BITCHES, Lesson 1: Integer Basics.
"Skybuck Flying"  2008-04-16 12:29:17 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 0:14:44 CDT 2008.