<div dir="ltr"><div class="gmail_default" style="font-size:small">Yes, h2pas essentially generates my second example.<br><br></div><div class="gmail_default" style="font-size:small">My question has more to do with using predefined enum constants as bitmasks in sets, instead of the default behaviour (which is to use the enum constant as the bit position instead of a bitmask).<br><br></div><div class="gmail_default" style="font-size:small">My previous suggestion {$EnumConstantsUseLiteral} makes no sense as a compiler mode flag; a better choice would be something like {$UseEnumConstantsAsBitmasksInSets}, or something even longer if possible. : -)<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Apr 2, 2016 at 2:06 AM, <a href="mailto:thaddy@thaddy.com">thaddy@thaddy.com</a> <span dir="ltr"><<a href="mailto:thaddy@thaddy.com" target="_blank">thaddy@thaddy.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
Well,<br>
<br>
h2pas gives you:<br>
{$packrecords c}<br>
<br>
type<br>
VkFlags = uint32_t;<br>
<br>
VkSparseImageFormatFlagBits =
(VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT := $00000001,<br>
VK_SPARSE_IMAGE_FORMAT_ALIGNED_MIP_SIZE_BIT := $00000002,<br>
VK_SPARSE_IMAGE_FORMAT_NONSTANDARD_BLOCK_SIZE_BIT := $00000004<br>
);<br>
<br>
VkSparseImageFormatFlags = VkFlags;<br>
<br>
<br>
<br>
<div>On 01-Apr-16 10:01 PM, Alcom wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div class="gmail_default" style="font-size:small"><br>
I'm working on some translated C headers for Vulkan for use in
FPC.<br>
<br>
In the vulkan.h header file, we have the following:<br>
<br>
typedef uint32_t VkFlags;<br>
typedef enum VkSparseImageFormatFlagBits {<br>
VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT =
0x00000001,<br>
VK_SPARSE_IMAGE_FORMAT_ALIGNED_MIP_SIZE_BIT =
0x00000002,<br>
VK_SPARSE_IMAGE_FORMAT_NONSTANDARD_BLOCK_SIZE_BIT =
0x00000004,<br>
} VkSparseImageFormatFlagBits;<br>
typedef VkFlags VkSparseImageFormatFlags;<br>
<br>
For code maintenance purposes, it is desirable to have a
header translation that is as close as possible to the source.
A reasonable translation to Pascal of this might be:<br>
<br>
TVkFlags = Cardinal;<br>
TVkSparseImageFormatFlagBits = <br>
(<br>
VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT = $00000001,<br>
VK_SPARSE_IMAGE_FORMAT_ALIGNED_MIP_SIZE_BIT =
$00000002,<br>
VK_SPARSE_IMAGE_FORMAT_NONSTANDARD_BLOCK_SIZE_BIT =
$00000004<br>
);<br>
TVkSparseImageFormatFlags = TVkFlags;<br>
<br>
<br>
However, this solution has only the *illusion* of being
strongly typed -- nothing about which the compiler is aware
links TVkImageCreateFlags with the TVkImageCreateFlagBits.<br>
<br>
A seemingly better solution (albeit incorrect) would be the
following:<br>
<br>
{$packset 4}<br>
TVkSparseImageFormatFlagBits = <br>
(<br>
VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT = $00000001,<br>
VK_SPARSE_IMAGE_FORMAT_ALIGNED_MIP_SIZE_BIT =
$00000002,<br>
VK_SPARSE_IMAGE_FORMAT_NONSTANDARD_BLOCK_SIZE_BIT =
$00000004<br>
);<br>
TVkSparseImageFormatFlags = set of
TVkSparseImageFormatFlagBits;<br>
<br>
This will not give the expected results, because FPC
interprets the enum constant as an exponent (or bit position,
if you prefer).<br>
<br>
<br>
<br>
My question is this: Is there currently a modifier for the set
declaration that instructs the compiler to accept the enum
values as literal constants, instead of interpreting them as
exponents?<br>
<br>
e.g. something like this:<br>
{$EnumConstantsUseLiteral}<br>
--or--<br>
TVkSparseImageFormatFlags = literalset of
TVkSparseImageFormatFlagBits;<br>
--or--<br>
TVkSparseImageFormatFlags = set of
TVkSparseImageFormatFlagBits; literal;<br>
--or--<br>
TVkSparseImageFormatFlags = set of literal
TVkSparseImageFormatFlagBits;<br>
<br>
</div>
</div>
<br>
<fieldset></fieldset>
<br>
<pre>_______________________________________________
fpc-devel maillist - <a href="mailto:fpc-devel@lists.freepascal.org" target="_blank">fpc-devel@lists.freepascal.org</a>
<a href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel" target="_blank">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>
</pre>
</blockquote>
<br>
</div>
<br>_______________________________________________<br>
fpc-devel maillist - <a href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a><br>
<a href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel" rel="noreferrer" target="_blank">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a><br>
<br></blockquote></div><br></div>