A
A
agorkov2012-02-07 13:51:27
Delphi
agorkov, 2012-02-07 13:51:27

Strange behavior of Delphi XE2?

I understand that Delphi is not particularly liked here, but as a teaching language it is not so bad. Not so long ago I had the chance to work with the newest version of the Delphi compiler.
Finally, it became possible to write 64-bit applications. And the question, in fact, is about such applications.
There is a code:
var
s1,s2: string;
begin
s1:='00000000';
s2:='00000000';
if s1=s2 then
writeln('Equal')
else
writeln('Not equal');
end;
This code compiled for 32 bit outputs "Equal", the same code compiled for 64 bit prints "Not Equal".
And if the terms s1, s2 are assigned '0000' and '0000', respectively, then regardless of the "bitness" of the application, "Not equal" will be displayed.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
AndreyDaeron, 2012-02-07
@AndreyDaeron

A simple program for 32 bits gives out "Not equal", which is generally correct. Delphi XE2 Update1

program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils;

var
s1,s2: string;

begin
  try
    s1:='00000000';
    s2:='00000001';
    if s1=s2 then
    writeln('Равны')
    else
    writeln('Не равны');
    Sleep(100000);
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

D
dimmaq, 2012-02-07
@dimmaq

What does the compiler generate? Put a dot on s1:=, run and press ALT+CTRL+C.
Here is for 32bit:

Project1.dpr.9: s1:='00000000';
0045E31A B86C9B4600       mov eax,$00469b6c
0045E31F BAA0E34500       mov edx,$0045e3a0
0045E324 E80F6AFAFF       call @LStrAsg
Project1.dpr.10: s2:='00000000';
0045E329 B8709B4600       mov eax,$00469b70
0045E32E BAA0E34500       mov edx,$0045e3a0
0045E333 E8006AFAFF       call @LStrAsg
Project1.dpr.11: if s1=s2 then
0045E338 A16C9B4600       mov eax,[$00469b6c]
0045E33D 8B15709B4600     mov edx,[$00469b70]
0045E343 E8A06DFAFF       call @LStrCmp
0045E348 751B             jnz $0045e365

P
Pyatochkin, 2012-02-07
@Pyatochkin

it’s xe2 that doesn’t exist and I can’t check it, but there is an amusing document lying on embarcodero , on your question, you can try to read from the middle of page 24 and the beginning of the 25th ...

A
AndreyDaeron, 2012-02-09
@AndreyDaeron

Got home to x64:

program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils;

var
s1,s2: string;

begin
  try
    s1:='00000000';
    s2:='00000000';
    if s1=s2 then
    writeln('Равны')
    else
    writeln('Не равны');
    Sleep(100000);
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


Outputs are equal.
The usual XE2 with Update 3, for x64 there is a standard paserver.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question