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 > Lesson 3, Integ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 3699 of 3851
Post > Topic >>

Lesson 3, Integer Assignments, Signed to Unsigned with Mixed Sizes.

by "Skybuck Flying" <BloodyShame@[EMAIL PROTECTED] > Apr 17, 2008 at 03:52 AM

See comments or see website for details:

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

// *** Begin of AnalysisLesson3.dpr ***

program AnalysisLesson3;

{$APPTYPE CONSOLE}

{

Version 0.01 created on 17 april 2008 by Skybuck Flying

Lesson 3, Integer Assignments, Signed to Unsigned with Mixed Sizes.

Conclusions:

Out of range detection at runtime for assignments via variables, OK
Out of range detection at compiletime for assignments via constants, OK 
except one:

Uint32 := -100000000000; // not detected at compile time, but still
detected 
at runtime.

Platform tested intel architecture 32.

47 out of 48 tests passed.
1 out of 48 tests doubtfull. (0.5 points)

Score:

9.9 out of 10

}

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;

 vInt8 : Tint8;
 vUint8 : Tuint8;

 vInt16 : Tint16;
 vUint16 : Tuint16;

 vInt32 : Tint32;
 vUint32 : Tuint32;

 vInt64 : Tint64;
 vUint64 : Tuint64;
begin
 writeln('Program Started');
 writeln;

 // setup min and max for int8
 vMinInt8 := -128;
 vMaxInt8 := 127;

 // setup min and max for uint8
 vMinUint8 := 0;
 vMaxUint8 := 255;

 // setup min and max for int16
 vMinInt16 := -32768;
 vMaxInt16 := 32767;

 // setup min and max for uint16
 vMinUint16 := 0;
 vMaxUint16 := 65535;

 // setup min and max for int32
 vMinInt32 := -2147483648;
 vMaxInt32 := 2147483647;

 // setup min and max for uint32
 vMinUint32 := 0;
 vMaxUint32 := 4294967295;

 // setup min and max for int64
 vMinInt64 := -9223372036854775808;
 vMaxInt64 := 9223372036854775807;

 // test min and max for uint64
 vMinUint64 := 0;
 vMaxUint64 := 18446744073709551615;

 // test doubtfull assignments, like mixing types and/or sizes.

 // unsigned 8 bit = negative signed variable bit

 // (enable the writeln down below to start testing a specific section)

 // TEST 1
// vUint8 := vMinInt8; // Run error: Range Check Error, OK

 // TEST 2
// vUint8 := -100; // Compile error: Constant expression violates subrange

bounds, OK

 // TEST 3
// vUint8 := vMaxInt8; // Result: 127, OK

 // TEST 4
// vUint8 := vMinInt16; // Run error: Range Check Error, OK

 // TEST 5
// vUint8 := -10000; // Compile error: Constant expression violates
subrange 
bounds, OK

 // TEST 6
// vUint8 := vMaxInt16; // Run error: Range Check Error, OK

 // TEST 7
// vUint8 := vMinInt32; // Run error: Range Check Error, OK

 // TEST 8
// vUint8 := -1000000; // Compile error: Constant expression violates 
subrange bounds, OK

 // TEST 9
// vUint8 := vMaxInt32; // Run error: Range Check Error, OK

 // TEST 10
// vUint8 := vMinInt64; // Run error: Range Check Error, OK

 // TEST 11
// vUint8 := -100000000000; // Compile error: Constant expression violates

subrange bounds, OK

 // TEST 12
// vUint8 := vMaxInt64; // Run error: Range Check Error, OK

// writeln( 'vUint8: ', vUint8 );

 // unsigned 16 bit := negative signed variable bit

 // TEST 13
// vUint16 := vMinInt8; // Run error: Range Check Error, OK

 // TEST 14
// vUint16 := -100; // Compile error: Constant expression violates
subrange 
bounds, OK

 // TEST 15
// vUint16 := vMaxInt8; // Result: 127, OK

 // TEST 16
// vUint16 := vMinInt16; // Run error: Range Check Error, OK

 // TEST 17
// vUint16 := -1000; // Compile error: Constant expression violates
subrange 
bounds, OK

 // TEST 18
// vUint16 := vMaxInt16; // Result: 32767, OK

 // TEST 19
// vUint16 := vMinInt32; // Run error: Range Check Error, OK

 // TEST 20
// vUint16 := -1000000; // Compile error: Constant expression violates 
subrange bounds, OK

 // TEST 21
// vUint16 := vMaxInt32; // Run error: Range Check Error, OK

 // TEST 22
// vUint16 := vMinInt64; // Run error: Range Check Error, OK

 // TEST 23
// vUint16 := -100000000000; // Compile error: Constant expression
violates 
subrange bounds, OK

 // TEST 24
// vUint16 := vMaxInt64; // Run error: Range Check Error, OK

// writeln( 'vUint16: ', vUint16 );

 // unsigned 32 bit := negative signed variable bit

 // TEST 25
// vUint32 := vMinInt8; // Run error: Range Check Error, OK

 // TEST 26
// vUint32 := -100; // Compile error: Constant expression violates
subrange 
bounds, OK

 // TEST 27
// vUint32 := vMaxInt8; // Result: 127, OK

 // TEST 28
// vUint32 := vMinInt16; // Run error: Range Check Error, OK

 // TEST 29
// vUint32 := -10000; // Compile error: Constant expression violates 
subrange bounds, OK

 // TEST 30
// vUint32 := vMaxInt16; // Result: 32767, OK

 // TEST 31
// vUint32 := vMinInt32; // Run error: Range Check Error, OK

 // TEST 32
// vUint32 := -1000000; // Compile error: Constant expression violates 
subrange bounds, OK

 // TEST 33
// vUint32 := vMaxInt32; // Result: 2147483647, OK

 // TEST 34
// vUint32 := vMinInt64; // Run error: Range Check Error, OK

 // TEST 35
// vUint32 := -100000000000; // NO COMPILE ERROR, But is catched by Range 
Check Error, SEMI-OK, SEMI-BAD.

 // TEST 36
// vUint32 := vMaxInt64; // Run error: Range Check Error, OK

// writeln( 'vUint32: ', vUint32 );

 // unsigned 64 bit := negative signed variable bit

 // TEST 37
// vUint64 := vMinInt8; // Run error: Range Check Error, OK

 // TEST 38
// vUint64 := -100; // Compile error: Constant expression violates
subrange 
bounds, OK

 // TEST 39
// vUint64 := vMaxInt8; // Result: 127, OK

 // TEST 40
// vUint64 := vMinInt16; // Run error: Range Check Error, OK

 // TEST 41
// vUint64 := -10000; // Compile error: Constant expression violates 
subrange bounds, OK

 // TEST 42
// vUint64 := vMaxInt16; // Result: 32767, OK

 // TEST 43
// vUint64 := vMinInt32; // Run error: Range Check Error, OK

 // TEST 44
// vUint64 := -1000000; // Compile error: Constant expression violates 
subrange bounds, OK

 // TEST 45
// vUint64 := vMaxInt32; // Result: 2147483647, OK

 // TEST 46
// vUint64 := vMinInt64; // Run error: Range Check Error, OK

 // TEST 47
// vUint64 := -100000000000; // Compile error: Constant expression
violates 
subrange bounds, OK

 // TEST 48
 vUint64 := vMaxInt64; // Result: 9223372036854775807, OK

 writeln( 'vUint64: ', vUint64 );

 writeln('Program finished');
end;

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

// *** End of AnalysisLesson3.dpr ***

Bye,
  Skybuck.
 




 1 Posts in Topic:
Lesson 3, Integer Assignments, Signed to Unsigned with Mixed Siz
"Skybuck Flying"  2008-04-17 03:52:00 

Post A Reply:
  Go here to Signup

AddThis Feed Button


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

Contact
tan12V112 Thu Jul 24 13:45:48 CDT 2008.