<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#ffffff">
On 07/07/2011 11:43, Mattias Gaertner wrote:
<blockquote
cite="mid:1659322445.470099.1310035390960.JavaMail.open-xchange@cc-app1"
type="cite">
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<title></title>
<p style="margin: 0px;">You don't need the future. You can already
create a crash using const shortstring:</p>
</blockquote>
<br>
Indeed, thanks for the example.<br>
<br>
And with this example there is another potential issue arising from
not honouring the contract of const.<br>
<br>
The behaviour of such code may change at random depending on
fpc-version or optimization. Future versions of fpc could cahce the
result of "h<>''" (as this expression is constant too), and
re-use it in the 2nd IF.<br>
So mis-honouring the rules of how to use "const" does not only lead
to potential crashes, but it also leads to code that has no defined
behaviour, and may lead to completely random results.<br>
<br>
This means the current behaviour with ansistring is absolutely
right. It is only a consequence of the behaviour already observed
with other types.<br>
<br>
<br>
<br>
<blockquote
cite="mid:1659322445.470099.1310035390960.JavaMail.open-xchange@cc-app1"
type="cite">
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">{$mode objfpc}{$H+}<br>
uses Classes;<br>
var<br>
s: shortstring = '';<br>
o: TStringList = nil;<br>
<br>
procedure DoSomething(const h: shortstring);<br>
begin<br>
if h<>'' then<br>
o:=TStringList.Create; // not called, because s=h=''<br>
s:='A';<br>
if h<>'' then<br>
writeln(o.Count); // called, because now s=h='A' => crash<br>
end;<br>
<br>
begin<br>
DoSomething(s);<br>
end.</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"> </p>
<div style="margin: 5px 0px;"> >[...] </div>
<br>
<br>
Mattias<br>
<br>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
fpc-devel maillist - <a class="moz-txt-link-abbreviated" href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>
<a class="moz-txt-link-freetext" href="http://lists.freepascal.org/mailman/listinfo/fpc-devel">http://lists.freepascal.org/mailman/listinfo/fpc-devel</a>
</pre>
</blockquote>
<br>
</body>
</html>