[fpc-pascal] C Enum vs. Integer
Johann Glaser
Johann.Glaser at gmx.at
Thu Sep 13 21:39:18 CEST 2012
Hi!
Am Donnerstag, den 13.09.2012, 15:45 +0200 schrieb Jonas Maebe:
> Guillermo Martínez Jiménez wrote on Thu, 13 Sep 2012:
>
> >> On 12 Sep 2012, at 19:11, Johann Glaser wrote:
> >>
> >>> Can I translate this 1:1, i.e., define an Enum in Pascal and just ignore
> >>> the compiler warnings about reused values?
> >>>
> >>> Or should I rather define all these types as Integer and define
> >>> constants for all values?
> >>
> >> It depends on whether you need arithmetic or not. If you do, use
> >> integer constants, otherwise you can use an enum.
> >
> > Actually you cannot. FPC optimizes enumerations in some cases (i.e.
> > in Delphi mode) but GCC uses 32bit for enumerations alwais.
>
> The size of an enum in gcc depends on whether or not the -fshort-enums
> command line option is used, and on the number of bits required to
> represent its upper bound value.
>
> > Anyway you can still use enums, but telling to FPC that you want to
> > set its size by directives $PACKENUM and $ENUMSIZE.
>
> It's $PACKENUM *or* $ENUMSIZE (they affect the same compiler setting)
>
> Anwyay, yes, that's also what I said the part of my original mail that
> you cut away.
Thank you all for your valuable information!
I found that libusb doesn't use the enum types anywhere but use uint8_t
or int instead. So I use constants for everything now.
Only one enum is used (libusb_transfer_status) in two structs, so I
replaced it as it was an int.
@Stephano: Thanks for the link with contributed units. Actually, one of
the USB units is from me, but a bit outdated. When my libusb 1.0
translation (including an OOP wrapper) is done I'll update
http://wiki.freepascal.org/Hardware_Access#libusb and the contributed
units page again.
Thanks
Hansi
More information about the fpc-pascal
mailing list