Модератор: Модераторы
Kemet писал(а):результат будет зависеть от битности системы
function SixtyThree: UInt64;
begin
SixtyThree := 63;
end;
var
U: UInt64;
begin
U := UInt64(1) shl SixtyThree;
Writeln(BinStr(U, 64));
end.
function SixtyThree: UInt64;
begin
SixtyThree := 63;
end;
var
U: UInt64;
begin
U := Ord(True) shl SixtyThree;
Writeln(BinStr(U, 64));
end.
type
E = (Zero = 0, One = 1);
function SixtyThree: UInt64;
begin
SixtyThree := 63;
end;
var
U: UInt64;
begin
U := Ord(One) shl SixtyThree;
Writeln(BinStr(U, 64));
end.
iskander писал(а):PS
RAD Studio 10.3 Rio писал(а):
Note that the value of y is interpreted modulo the size of the type of x.
Thus for example, if x is an integer, x shl 40 is interpreted as x shl 8 because an integer is 32 bits and 40 mod 32 is 8.
А какое? ))) Компилятор же не знает чего об этом думает программист, поэтому вынужден следовать определенному соглашению, например, что все числовые константы это знаковое целое.Дож писал(а):А что, константа 1 -- это знаковое?
Дож писал(а):Ни та, ни другая не выдают того, что ожидает наивный программист (!)
Kemet писал(а): потому что константное выражение, а оно, вроде как, считается в 64 бит всегда
Хз, возможно из-за того, что E это пользовательский тип, фрипаскаль обрабатывает выражение как-то иначе, нужно с Дельфи сравнитьДож писал(а):Тогда почему разные результаты? И там, и там Ord
FPC evaluates constant expressions always using 64 bit arithmetic in all modes, and has done so since the moment it supported 64 bit arithmetic. If you use WriteLn(int64(i) shr 32);, you'll also get 0 in the second case. Changing that would break backwards FPC compatibility. It also wouldn't surprise me if Delphi XE3 would give the same output as FPC.
Const
c1 = 22;
c2 = 33.33;
c3 = 2200000000;
c4 = 9200000000000000;
Begin
WriteLn(sizeof(c1));
WriteLn(sizeof(c2));
WriteLn(sizeof(c3));
WriteLn(sizeof(c4));
End.
Вернуться в Free Pascal Compiler
Сейчас этот форум просматривают: Yandex [Bot] и гости: 5