|
From: TheDevil on 12 Apr 2008 16:04 Hello, See comments for details. // *** Begin of Main.CPP #include <stdio.h> typedef char int8; typedef short int int16; typedef int int32; typedef long long int64; typedef unsigned char uint8; typedef unsigned short uint16; typedef unsigned int uint32; typedef unsigned long long uint64; /* 13 april 2008 Back to School: Lesson 4, Integer Assignments, Unsigned to Signed with Mixed Sizes. Conclusions: BAD: 2 spectacular range detection failures for int32. BAD: 2 spectacular range detection failures for int64. BAD: 1 range detection failure for int8. BAD: 1 range detection failure for int16. Platform tested intel architecture 32. 40 out of 48 tests passed. 2 out of 48 tests doubtfull, but passed. 6 out of 48 tests failed. Score: 8.75 out of 10 */ int main() { printf("Program Started \n\n"); int8 vMinInt8; int8 vMaxInt8; uint8 vMinUint8; uint8 vMaxUint8; int16 vMinInt16; int16 vMaxInt16; uint16 vMinUint16; uint16 vMaxUint16; int32 vMinInt32; int32 vMaxInt32; uint32 vMinUint32; uint32 vMaxUint32; int64 vMinInt64; int64 vMaxInt64; uint64 vMinUint64; uint64 vMaxUint64; int8 vInt8; uint8 vUint8; int16 vInt16; uint16 vUint16; int32 vInt32; uint32 vUint32; int64 vInt64; uint64 vUint64; // 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; // same as -2147483648, solves warning, <- weakness in language. vMaxInt32 = 2147483647; // setup min and max for uint32 vMinUint32 = 0; vMaxUint32 = 4294967295; // setup min and max for int64 vMinInt64 = 9223372036854775808; // same as -9223372036854775808, solves warning, <- weakness in language vMaxInt64 = 9223372036854775807; // 9223372036854775808 would give no warning ?!?!, BAD // test min and max for uint64 vMinUint64 = 0; vMaxUint64 = 18446744073709551615; // signed 8 bit = unsigned variable bit // TEST1 // vInt8 = vMinUint8; // no warning, OK // // result: 0, OK // TEST2 // vInt8 = 200; // warning: truncation of constant value, OK // TEST3 // vInt8 = vMaxUint8; // no warning, BAD // result: -1, OK // TEST4 // vInt8 = vMinUint16; // warning: conversion from 'uint16' to 'int8', possible loss of data, OK // result: 0, OK // TEST5 // vInt8 = 50000; // warning: truncation from 'int' to 'int8', OK // warning: truncation of constant value, OK // TEST6 // vInt8 = vMaxUint16; // warning: conversion from 'uint16' to 'int8', possible loss of data, OK // result: -1, OK // TEST 7 // vInt8 = vMinUint32; // warning: conversion from 'uint32' to 'int8', possible loss of data, OK // result: 0, OK // TEST 8 // vInt8 = 3000000000; // warning: truncation from 'unsigned long' to 'int8', OK, INTERESTING // warning: truncation of constant value, OK // TEST 9 // vInt8 = vMaxUint32; // warning: conversion from 'uint32' to 'int8', possible loss of data, OK // result: -1, OK // TEST 10 // vInt8 = vMinUint64; // warning: conversion from 'uint64' to 'int8', possible loss of data, OK // result: 0, OK // TEST 11 // vInt8 = 12345678901234567890; // warning: truncation from 'unsigned __int64' to 'int8', OK, INTERESTING // warning: truncation of constant value, OK // TEST 12 // vInt8 = vMaxUint64; // warning: conversion from 'uint64' to 'int8', possible loss of data, OK // result: -1, OK // printf("vInt8: %d \n", vInt8 ); // signed 16 bit = unsigned variable bit // TEST 13 // vInt16 = vMinUint8; // no warning, OK // result: 0, OK // TEST 14 // vInt16 = 200; // no warning, OK // TEST 15 // vInt16 = vMaxUint8; // no warning, OK // result: 255, OK // TEST 16 // vInt16 = vMinUint16; // no warning, OK // result: 0, OK // TEST 17 // vInt16 = 50000; // warning: truncation of constant value // TEST 18 // vInt16 = vMaxUint16; // no warning, BAD // result: -1, OK // TEST 19 // vInt16 = vMinUint32; // warning: conversion from 'uint32' to 'int16', possible loss of data, OK // result: 0, OK // TEST 20 // vInt16 = 3000000000; // warning: truncation from 'unsigned long' to 'int16', OK // warning: truncation of constant value, OK // TEST 21 // vInt16 = vMaxUint32; // warning: conversion from 'uint32' to 'int16', possible loss of data, OK // result: -1, OK // TEST 22 // vInt16 = vMinUint64; // warning: conversion from 'uint64' to 'int16', possible loss of data, OK // result: 0, OK // TEST 23 // vInt16 = 12345678901234567890; // warning: truncation from 'unsigned __int64' to 'int16', OK // warning: truncation of constant value // TEST 24 // vInt16 = vMaxUint64; // warning: conversion from 'uint64' to 'int16', possible loss of data, OK // result: -1, OK // printf("vInt16: %d \n", vInt16 ); // signed 32 bit = unsigned variable bit // TEST 25 // vInt32 = vMinUint8; // no warning: OK // result: 0, OK // TEST 26 // vInt32 = 200; // no warning, OK // TEST 27 // vInt32 = vMaxUint8; // no warning, OK // result: 255, OK // TEST 28 // vInt32 = vMinUint16; // no warning, OK // result: 0, OK // TEST 29 // vInt32 = 50000; // no warning, OK // TEST 30 // vInt32 = vMaxUint16; // no warning, OK // result: 65535, OK // TEST 31 // vInt32 = vMinUint32; // no warning, DOUBTFULLL, BUT OK. // TEST 32 // vInt32 = 3000000000; // no warning, VERY BAD, SPECTACULAR FAILURE // result: -1294967296, OK // TEST 33 // vInt32 = vMaxUint32; // no warning, VERY BAD, SPECTACULAR FAILURE // result: -1, OK // TEST 34 // vInt32 = vMinUint64; // warning: conversion from 'uint64' to 'int32', possible loss of data, OK // result: 0, OK // TEST 35 // vInt32 = 12345678901234567890; // warning: truncation from 'unsigned __int64' to 'int32', OK // warning: truncation of constant value, OK // TEST 36 // vInt32 = vMaxUint64; // warning: conversion from 'uint64' to 'int32', possible loss of data, OK // result: -1, OK // printf("vInt32: %d \n", vInt32 ); // signed 64 bit = unsigned variable bit // TEST 37 // vInt64 = vMinUint8; // no warning, OK // result: 0, OK // TEST 38 // vInt64 = 200; // no warning, OK // TEST 39 // vInt64 = vMaxUint8; // no warning, OK // result: 255, OK // TEST 40 // vInt64 = vMinUint16; // no warning, OK // result: 0, OK // TEST 41 // vInt64 = 50000; // no warning, OK // TEST 42 // vInt64 = vMaxUint16; // no warning, OK // result: 65535, OK // TEST 43 // vInt64 = vMinUint32; // no warning, OK // result: 0, OK // TEST 44 // vInt64 = 3000000000; // no warning, OK // result: 3000000000, OK, SLIGHTY INTERESTING // TEST 45 // vInt64 = vMaxUint32; // no warning, OK // result: 4294967295, OK // TEST 46 // vInt64 = vMinUint64; // no warning, DOUBTFULL, BUT OK // result: 0, OK // TEST 47 // vInt64 = 12345678901234567890; // no warning, VERY BAD, SPECTACULAR FAILURE // result: -6101065172474983726, OK // TEST 48 vInt64 = vMaxUint64; // no warning, VERY BAD, SPECTACULAR FAILURE // result: -1, OK printf("vInt64: %lld \n", vInt64 ); printf("Program finished \n"); } // *** End of Main.cpp *** Bye, The Devil.
|
Pages: 1 Prev: i need help Next: Lesson 5, Arrays, Static, Dynamic, Multi Dimesional. |