* don't call the ansistring val variant for a zero based array if not necessary to avoid ansistring usage in embedded applications

git-svn-id: trunk@25283 -
This commit is contained in:
florian 2013-08-18 17:04:06 +00:00
parent 38f3448e22
commit a2a405581c
2 changed files with 9 additions and 2 deletions

View File

@ -1553,8 +1553,9 @@ implementation
{ the shortstring-longint val routine by default }
if (sourcepara.resultdef.typ = stringdef) then
procname := procname + tstringdef(sourcepara.resultdef).stringtypname
{ zero-based arrays (of char) can be implicitely converted to ansistring }
else if is_zero_based_array(sourcepara.resultdef) then
{ zero-based arrays (of char) can be implicitely converted to ansistring, but don't do
so if not needed because the array is too short }
else if is_zero_based_array(sourcepara.resultdef) and (sourcepara.resultdef.size>255) then
procname := procname + 'ansistr'
else
procname := procname + 'shortstr';

View File

@ -13,8 +13,10 @@ var
Code : Integer;
D : Double;
s : Array[byte] of Char;
s2 : Array[0..100] of Char;
begin
s := '123';
s2 := '123';
test(s);
Val(s, D, Code); // compiles only in delphi
if (abs(d-123.0) > 0.00001) then
@ -22,4 +24,8 @@ begin
Val(PChar(@s), D, Code); // compiles in both delphi and FPC
if (abs(d-123.0) > 0.00001) then
halt(1);
Val(s2, D, Code); // compiles only in delphi
if (abs(d-123.0) > 0.00001) then
halt(1);
writeln('ok');
end.