Why does a programming language allow you to assign a short integer?

program TypeCategory;
{$R+}
var
    sInt : shortint;
    iInt : integer;
begin
    readln(iInt);
    sInt := iInt;
    writeln(sInt);
end.

Given the above example, pascal allows you to assign from integerto shortintor even from longintto shortintwithout casting type explication. That is, pascal allows assignment within a type category (here integer types).

Pascal is famous for his strongly typed, but why does he allow this type weakly typed? I think that such syntax will encourage inconsistent code.

What are the benefits of this syntax? Are there any other languages ​​that used this syntax besides the famous C and C ++?

thanks.

:
turbo pascal free pascal with fpc/objfpc/tp/delphi model. , gcc/g++ msvc . , int ( 4 ) short int ( 2) , , possible lose of data.

+5
5

1.

, "pascal"? ISO Pascal . - , , .

- ( Teun D) . .

, , , .

, " ", :

Luca Cardelli . ; .

( ) . ... , , . =)

2.

, , , .

- , , C ++?

, . SHORTINT . , 1 ... , 1 . 4 INTEGER 2- SHORTINT. 4 2 . , , .

Wirth Oberon-07 (Language Report, PDF). - 32- INTEGER.

Python ( - ) int, , () .

, - - 70 . =)

?

- () . , , , -2 ( SHORT() LONG()), . . . - (shortint) <= size (int). .

3. -2 =)

, . , Oberon-2 .

6 . :

3-5 , 6 7 , . ; () : LONGREAL >= REAL >= LONGINT >= INTEGER >= SHORTINT

9 :

, A:

e Te , v Tv, :

Te Tv ;

Te Tv - , Tv Te;

...

, . INTEGER SHORTINT. , Component Pascal, Oberon-2. BlackBox Component Builder - IDE Windows.


.

, , () : LONGREAL >= REAL >= LONGINT >= INTEGER >= SHORTINT, , LONGINTS, "REAL".

LONGINTS, "REAL" s

IDE, ,

MAX (LONGINT) = 9223372036854775807

MAX (REAL) = 1.797693134862316E + 308

, LONGINT REAL-. . , , . REAL INTEGER - . . . . ( ), - . IEEE ( IEEE 754) .

, REAL , , IEEE 754. " " , .

... =)

+8

, , , . , . , .

+2

, , shortint, integer. ( ).

, , Pascal . . #, (http://msdn.microsoft.com/en-us/library/khy08726(VS.71).aspx), . , .

0

int short int,

var
sInt : shortint;
iInt : integer;

if (iInt < 100 && iInt > -100)
{
   sInt := iInt; // this would not compile
}

var
sInt : shortint;
iInt : integer;

sInt := (iInt & 0xFFFF); // this would not compile

, ints int, .

var
sInt1 : shortint;
sInt2 : shortint;
iInt : integer;

/* I want to multiply sInt2 by sInt1 and then divide by 100 */
iInt = sInt2;
sInt2 := (iInt * sInt1) / 100; // this would not compile

, , - .

0

, , :

  • Pascal, integer, . - , , . , Rangechecks .
  • Pascal , . . ( , ), . , ( ), real .

, . ( ), , , . , , , (), , . . , . , - . , , .

.

var x : 0..10;

x:=10;
x:=x+1; // runtime range check error  here.

, DOS . Turbo Pascal "", ( ).

( int64 Delphi. , int128 x86_64 ), ( . unsigned type, , ( Pascal , , )

0
source

All Articles