<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 16.07.2017 23:11, Florian Klämpfl
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:abebad06-9a67-5850-b3b4-5b7f21832da6@freepascal.org">
<pre wrap="">Am 16.07.2017 um 22:39 schrieb Florian Klämpfl:
</pre>
<blockquote type="cite">
<pre wrap="">Am 16.07.2017 um 22:15 schrieb Martok:
</pre>
<blockquote type="cite">
<pre wrap="">
However:
---------------------------
{$mode objfpc}
type
TExplEnum = (a=1, b=3, c=5, d=7);
TSubEnum = a..d;
TEnArr = array[TSubEnum] of Byte;
begin
WriteLn('SizeOf(TEnArr) = ', SizeOf(TEnArr));
WriteLn('Low(TEnArr) = ', Low(TEnArr), ', ', Ord(Low(TEnArr)));
WriteLn('High(TEnArr) = ', High(TEnArr), ', ', Ord(High(TEnArr)));
end.
---------------------------
SizeOf(TEnArr) = 7
Low(TEnArr) = a, 1
High(TEnArr) = d, 7
---------------------------
That difference was unexpected. At least for me.
</pre>
</blockquote>
<pre wrap="">
Indeed, this is a bug. IMO the declaration of TSubEnum should not be allowed.
</pre>
</blockquote>
<pre wrap="">
I made a patch and tested it, however, this causes regressions in our tests, so I am not sure if it
should be changed.</pre>
</blockquote>
<br>
It must not be changed. Delphi documentation is clear about this
case:
<a class="moz-txt-link-freetext" href="http://docwiki.embarcadero.com/RADStudio/XE5/en/Simple_Types#Enumerated_Types_with_Explicitly_Assigned_Ordinality">http://docwiki.embarcadero.com/RADStudio/XE5/en/Simple_Types#Enumerated_Types_with_Explicitly_Assigned_Ordinality</a><br>
<br>
<i>type Size = (Small = 5, Medium = 10, Large = Small + Medium);</i><i><br>
</i><i>defines a type called Size whose possible values include
Small, Medium, and Large, where Ord(Small) returns 5, Ord(Medium)
returns 10, and Ord(Large) returns 15.</i><i><br>
</i><i><b>An enumerated type is, in effect, a subrange whose lowest
and highest values correspond to the lowest and highest
ordinalities of the constants in the declaration. </b><b>In the
previous example, the Size type has 11 possible values whose
ordinalities range from 5 to 15. (Hence the type array[Size] of
Char represents an array of 11 characters.) Only three of these
values have names, but the others are accessible through
typecasts and through routines such as Pred, Succ, Inc, and Dec.</b></i><br>
<br>
Ondrej<br>
</body>
</html>