Article View: pl.comp.lang.pascal
Article #93120Wadliwy kod wynikowy
From: webmajsterek
Date: Tue, 12 Oct 2010 08:02
Date: Tue, 12 Oct 2010 08:02
66 lines
2453 bytes
2453 bytes
taki przykladowy program -- pokazuje że fpc w złej kolejnosci wywoluje funkcje
zawarte w wywołaniu procedury .
program error;
{$APPTYPE CONSOLE}
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes
{ you can add units after this };
{$R *.res}
const tab:array[0..9]of byte =(0,1,2,3,4,5,6,7,8,9);
var Count:Integer;
Function ReturnByte:Byte;
begin
If Count>9 then Count:=0;
Result:=Tab[Count];
Count:=Count+1;
end;
procedure WriteByte(S:String;a,b,c,d:Byte);
begin
WriteLn(S,a,' ',b,' ',c,' ',d);
end;
var a,b:Byte;
begin
Count:=0;
WriteLn (' Orginal ',tab[0],' ',Tab[1],' ',Tab[2],' ',Tab[3]);
WriteByte(' Bad Result ', ReturnByte,ReturnByte,ReturnByte,ReturnByte);
WriteLn (' Orginal ',tab[4],' ',Tab[5],' ',Tab[6],' ',Tab[7]);
a:= ReturnByte;
WriteByte(' Bad Result ', a,ReturnByte,ReturnByte,ReturnByte);
WriteLn (' Orginal ',tab[8],' ',Tab[9],' ',Tab[0],' ',Tab[1]);
a:= ReturnByte;
b:= ReturnByte;
WriteByte(' Good Result ', a,b,ReturnByte,ReturnByte);
Readln;
end.
na
http://wiki.freepascal.org/Code_Conversion_Guide#Order_of_parameter_evaluation
pisza ze
"Delphi gwarantuje, że wszystkie parametry są obliczane od lewej do prawej. FPC
nie zawiera takich gwarancji, a może wywołać parametry w dowolnej kolejności w
celu wytworzenia optymalnego kodu."
I tu problem bo w 99.99 % przypadków wywołań kolejność ma znaczenie .
--
Wysłano z serwisu OnetNiusy: http://niusy.onet.pl
Technical Details
Message-ID:
<7d75.00000e7e.4cb41604@newsgate.onet.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!agh.edu.pl!news.agh.edu.pl!news.onet.pl!newsgate.onet.pl!niusy.onet.plShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!agh.edu.pl!news.agh.edu.pl!news.onet.pl!newsgate.onet.pl!niusy.onet.pl From: webmajsterek@poczta.onet.pl Newsgroups: pl.comp.lang.pascal Subject: Wadliwy kod wynikowy Date: Tue, 12 Oct 2010 10:02:12 +0200 Organization: Onet.pl Lines: 66 Sender: news@newsgate.onet.pl Message-ID: <7d75.00000e7e.4cb41604@newsgate.onet.pl> NNTP-Posting-Host: newsgate.onet.pl Mime-Version: 1.0 X-Trace: newsgate.onet.pl 1286870532 17175 213.180.130.18 (12 Oct 2010 08:02:12 GMT) X-Complaints-To: niusy@onet.pl NNTP-Posting-Date: Tue, 12 Oct 2010 08:02:12 +0000 (UTC) X-Mailer: http://niusy.onet.pl X-Forwarded-For: 79.191.112.205, 10.174.28.59 X-User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; FDM; ie8_onetbuild_xppl) Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit