发现:d2006的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;
source.y2 := 20;
normal_r := source;
inlined_r := source;
normal(normal_r, -normal_r.x2, -normal_r.y2);
inlined(inlined_r, -inlined_r.x2, -inlined_r.y2);
compare(normal_r, inlined_r);
end;
var
s: string;
begin
{ TODO -oUser -cConsole Main : Insert code here }
test_failed();
test_failed2();
test_success();
writeln('press ENTRY to continue..');
readln(s);
end.
/////////////////////////////
/// other unit
/////////////////////////////
unit other_unit;
interface
uses
SysUtils, Types;
type
my_type = record //or object
x1, y1, x2, y2: integer;
end;
procedure inlined(var k: my_type; delta_x, delta_y: integer); inline;
procedure inlined2(var k: my_type; delta_x, delta_y: integer); inline;
implementation
procedure inlined(var k: my_type; delta_x, delta_y: integer);
begin
inc(k.x1, delta_x);
inc(k.x2, delta_x);
inc(k.y1, delta_y);
inc(k.y2, delta_y);
end;
procedure inlined2(var k: my_type; delta_x, delta_y: integer);
begin
k.x1 := k.x1 + delta_x;
k.x2 := k.x2 + delta_x;
k.y1 := k.y1 + delta_y;
k.y2 := k.y2 + delta_y;
end;
end.
运行可以发现,inline版的函数没有正确被编译,产生这种情况的条件:
1. inline函数在别的单元
2. 调用时,k.x1,k.y1作为delta_x, delta_y的实际参数
相关推荐
详解CSS中的display:flex||inline-flex属性|56375.pdf
介绍 Flex是Flexible Box的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性。任何一个容器都可以指定为Flex布局。 flex: 将对象作为弹性伸缩盒显示 inline-flex:将对象作为内联块级弹性伸缩盒显示 flex示例代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Test</title> <style type="text/css"> .main{ width:200px; background-color: red
rollup-plugin-inline-js:使用inline-js进行汇总
rollu-plugin-inline-js 使用。 如果您使用汇总构建源并希望在构建时内联一些静态资产,这可能会很有用。 安装 npm install -D rollup-plugin-inline-js 用法 import inline from "rollup-plugin-inline-js" ; export default { input : "entry.js" , output : { file : "dist/output.js" , format : "es" } , plugins : [ inline ( ) ] } ; 该插件将替换源代码中的$inline指令,就像。 配置 .inline.js配置文件按预期工作。 原料药 该模块导出单个功能。 createPlugin const plugin = createPlug
CSS解决inline-block的错位问题
废话不多说 帖代码
posthtml-inline-favicon:PostHTML插件到内嵌图标
posthtml-inline-favicon posthtml-inline-favicon是用于posthtml-inline-favicon的插件。 前: < head > < link rel =" shortcut icon " href =" favicon.ico " /> </ head > 后: < head > < link rel =" icon " type =" image/png " href =" [removed]... " /> </ head > 安装 yarn add -D posthtml-inline-favicon # OR npm i posthtml-inline-favicon 用法 const fs = require ( 'fs' ) ; const posthtml = require (
菲尼克斯电气Inline IO产品选型速查表.pdf
菲尼克斯电气Inline IO产品选型速查表pdf,菲尼克斯电气Inline IO产品选型速查表


语言基础/算法/系统设计
