[fpc-devel] C flags, enums, sets, and the "Pascal way"

thaddy at thaddy.com thaddy at thaddy.com
Sat Apr 2 09:06:55 CEST 2016


Well,

h2pas gives you:
{$packrecords c}

   type
     VkFlags = uint32_t;

     VkSparseImageFormatFlagBits = 
(VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT := $00000001,
       VK_SPARSE_IMAGE_FORMAT_ALIGNED_MIP_SIZE_BIT := $00000002,
       VK_SPARSE_IMAGE_FORMAT_NONSTANDARD_BLOCK_SIZE_BIT := $00000004
       );

     VkSparseImageFormatFlags = VkFlags;



On 01-Apr-16 10:01 PM, Alcom wrote:
>
> I'm working on some translated C headers for Vulkan for use in FPC.
>
> In the vulkan.h header file, we have the following:
>
>     typedef uint32_t VkFlags;
>     typedef enum VkSparseImageFormatFlagBits {
>         VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT = 0x00000001,
>         VK_SPARSE_IMAGE_FORMAT_ALIGNED_MIP_SIZE_BIT = 0x00000002,
>         VK_SPARSE_IMAGE_FORMAT_NONSTANDARD_BLOCK_SIZE_BIT = 0x00000004,
>     } VkSparseImageFormatFlagBits;
>     typedef VkFlags VkSparseImageFormatFlags;
>
> 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:
>
>     TVkFlags = Cardinal;
>     TVkSparseImageFormatFlagBits =
>     (
>         VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT = $00000001,
>         VK_SPARSE_IMAGE_FORMAT_ALIGNED_MIP_SIZE_BIT = $00000002,
>         VK_SPARSE_IMAGE_FORMAT_NONSTANDARD_BLOCK_SIZE_BIT = $00000004
>     );
>     TVkSparseImageFormatFlags = TVkFlags;
>
>
> However, this solution has only the *illusion* of being strongly typed 
> -- nothing about which the compiler is aware links TVkImageCreateFlags 
> with the TVkImageCreateFlagBits.
>
> A seemingly better solution (albeit incorrect) would be the following:
>
>     {$packset 4}
>     TVkSparseImageFormatFlagBits =
>     (
>         VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT = $00000001,
>         VK_SPARSE_IMAGE_FORMAT_ALIGNED_MIP_SIZE_BIT = $00000002,
>         VK_SPARSE_IMAGE_FORMAT_NONSTANDARD_BLOCK_SIZE_BIT = $00000004
>     );
>     TVkSparseImageFormatFlags = set of TVkSparseImageFormatFlagBits;
>
> This will not give the expected results, because FPC interprets the 
> enum constant as an exponent (or bit position, if you prefer).
>
>
>
> 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?
>
> e.g. something like this:
>     {$EnumConstantsUseLiteral}
>     --or--
>     TVkSparseImageFormatFlags = literalset of 
> TVkSparseImageFormatFlagBits;
>     --or--
>     TVkSparseImageFormatFlags = set of TVkSparseImageFormatFlagBits; 
> literal;
>     --or--
>     TVkSparseImageFormatFlags = set of literal 
> TVkSparseImageFormatFlagBits;
>
>
>
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20160402/0397ca39/attachment.html>


More information about the fpc-devel mailing list