发现:d2006的inline不是很可靠解决方法
发现:d2006的inline不是很可靠
今天做一个函数发现一些怪事,通过调试发现,delphi2006的inline新语法在特定情况下会出现错误。我做了个测试程序,不知道有没有搞错,大家鉴定鉴定,如果真的有问题,大家以后使用时要小心哟
///////////////////////////
// project
///////////////////////////
program inline_err;
{$APPTYPE CONSOLE}
uses
SysUtils,
other_unit in 'other_unit.pas ';
procedure normal(var k: my_type; delta_x, delta_y: integer);
//没有inline的函数
begin
inc(k.x1, delta_x);
inc(k.x2, delta_x);
inc(k.y1, delta_y);
inc(k.y2, delta_y);
end;
procedure compare(normal_r, inlined_r: my_type);
//比较结果
begin
if (normal_r.x1 <> inlined_r.x1)
or (normal_r.x2 <> inlined_r.x2)
or (normal_r.y1 <> inlined_r.y1)
or (normal_r.y2 <> inlined_r.y2) then
writeln( 'Error ')
else
writeln( 'Ok ');
end;
procedure test_failed();
var
source, normal_r, inlined_r: my_type;
begin
source.x1 := 10;
source.x2 := 20;
source.y1 := 10;
source.y2 := 20;
normal_r := source;
inlined_r := source;
normal(normal_r, -normal_r.x1, -normal_r.y1);
inlined(inlined_r, -inlined_r.x1, -inlined_r.y1);
compare(normal_r, inlined_r);
end;
procedure test_failed2();
var
source, normal_r, inlined_r: my_type;
begin
source.x1 := 10;
source.x2 := 20;
source.y1 := 10;
source.y2 := 20;
normal_r := source;
inlined_r := source;
normal(normal_r, -normal_r.x1, -normal_r.y1);
inlined2(inlined_r, -inlined_r.x1, -inlined_r.y1);
compare(normal_r, inlined_r);
end;
procedure test_success();
var
source, normal_r, inlined_r: my_type;
begin
source.x1 := 10;
source.x2 := 20;
source.y1 := 10;
今天做一个函数发现一些怪事,通过调试发现,delphi2006的inline新语法在特定情况下会出现错误。我做了个测试程序,不知道有没有搞错,大家鉴定鉴定,如果真的有问题,大家以后使用时要小心哟
///////////////////////////
// project
///////////////////////////
program inline_err;
{$APPTYPE CONSOLE}
uses
SysUtils,
other_unit in 'other_unit.pas ';
procedure normal(var k: my_type; delta_x, delta_y: integer);
//没有inline的函数
begin
inc(k.x1, delta_x);
inc(k.x2, delta_x);
inc(k.y1, delta_y);
inc(k.y2, delta_y);
end;
procedure compare(normal_r, inlined_r: my_type);
//比较结果
begin
if (normal_r.x1 <> inlined_r.x1)
or (normal_r.x2 <> inlined_r.x2)
or (normal_r.y1 <> inlined_r.y1)
or (normal_r.y2 <> inlined_r.y2) then
writeln( 'Error ')
else
writeln( 'Ok ');
end;
procedure test_failed();
var
source, normal_r, inlined_r: my_type;
begin
source.x1 := 10;
source.x2 := 20;
source.y1 := 10;
source.y2 := 20;
normal_r := source;
inlined_r := source;
normal(normal_r, -normal_r.x1, -normal_r.y1);
inlined(inlined_r, -inlined_r.x1, -inlined_r.y1);
compare(normal_r, inlined_r);
end;
procedure test_failed2();
var
source, normal_r, inlined_r: my_type;
begin
source.x1 := 10;
source.x2 := 20;
source.y1 := 10;
source.y2 := 20;
normal_r := source;
inlined_r := source;
normal(normal_r, -normal_r.x1, -normal_r.y1);
inlined2(inlined_r, -inlined_r.x1, -inlined_r.y1);
compare(normal_r, inlined_r);
end;
procedure test_success();
var
source, normal_r, inlined_r: my_type;
begin
source.x1 := 10;
source.x2 := 20;
source.y1 := 10;