mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 17:29:21 +02:00
* 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:
parent
38f3448e22
commit
a2a405581c
@ -1553,8 +1553,9 @@ implementation
|
|||||||
{ the shortstring-longint val routine by default }
|
{ the shortstring-longint val routine by default }
|
||||||
if (sourcepara.resultdef.typ = stringdef) then
|
if (sourcepara.resultdef.typ = stringdef) then
|
||||||
procname := procname + tstringdef(sourcepara.resultdef).stringtypname
|
procname := procname + tstringdef(sourcepara.resultdef).stringtypname
|
||||||
{ zero-based arrays (of char) can be implicitely converted to ansistring }
|
{ zero-based arrays (of char) can be implicitely converted to ansistring, but don't do
|
||||||
else if is_zero_based_array(sourcepara.resultdef) then
|
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'
|
procname := procname + 'ansistr'
|
||||||
else
|
else
|
||||||
procname := procname + 'shortstr';
|
procname := procname + 'shortstr';
|
||||||
|
@ -13,8 +13,10 @@ var
|
|||||||
Code : Integer;
|
Code : Integer;
|
||||||
D : Double;
|
D : Double;
|
||||||
s : Array[byte] of Char;
|
s : Array[byte] of Char;
|
||||||
|
s2 : Array[0..100] of Char;
|
||||||
begin
|
begin
|
||||||
s := '123';
|
s := '123';
|
||||||
|
s2 := '123';
|
||||||
test(s);
|
test(s);
|
||||||
Val(s, D, Code); // compiles only in delphi
|
Val(s, D, Code); // compiles only in delphi
|
||||||
if (abs(d-123.0) > 0.00001) then
|
if (abs(d-123.0) > 0.00001) then
|
||||||
@ -22,4 +24,8 @@ begin
|
|||||||
Val(PChar(@s), D, Code); // compiles in both delphi and FPC
|
Val(PChar(@s), D, Code); // compiles in both delphi and FPC
|
||||||
if (abs(d-123.0) > 0.00001) then
|
if (abs(d-123.0) > 0.00001) then
|
||||||
halt(1);
|
halt(1);
|
||||||
|
Val(s2, D, Code); // compiles only in delphi
|
||||||
|
if (abs(d-123.0) > 0.00001) then
|
||||||
|
halt(1);
|
||||||
|
writeln('ok');
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user