[fpc-pascal] H2pas tool vs others, C header translation
Dmitry Boyarintsev
skalogryz.lists at gmail.com
Wed Aug 23 15:11:23 CEST 2017
On Wed, Aug 23, 2017 at 3:50 AM, Florian Klämpfl <florian at freepascal.org>
wrote:
> Am 22.08.2017 um 15:59 schrieb Martok:
> > As a heads-up: whatever tool you end up using, make sure you do NOT
> translate
> > the C enums in mpfr.h as enumerations. It will work, but create
> unpredictable
> > codegen on the FPC side.
>
> It is perfectly predictable. Just do not store invalid values in
> enumeration variables. And invalid
> is everything not being declared. This is how FPC works and will work.
Never saw FPC acting unpredictably.
(There was an issue back in the days with Delphi. But it's only because
delphi packs enumerations to 1 byte, where FPC packs them to 4 bytes in
objfpc mode)
Instead, I saw C-enumarations used as non-Pascal-enumerations. (which is
actually expected C<>Pascal).
For instance, it's common for C enumerations to be used used in bitwise
operations.
ENUM1 | ENUM2
(but report for sdl2 headers
https://github.com/ev1313/Pascal-SDL-2-Headers/issues/44)
not available in Pascal, unless an explicit type casting or sets are used.
So, in the end it's better to declare enumeration type elements as constant
and the type itself as an alias to integer (or cint)
thanks,
Dmitry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20170823/58ff5189/attachment.html>
More information about the fpc-pascal
mailing list