[fpc-pascal] Scoped enums and inferred types

Martok listbox at martoks-place.de
Wed Feb 21 10:37:21 CET 2018


> I doubt that many would be using scopedenums for that.
Isn't that what they're for?

{$SCOPEDENUMS ON}
type
  TTileSortingFlag = (Static,
                      Ramp,
                      Ignore,
                      Particle,
                      Floor,
                      Flat,
                      Container,
                      OnRamp,
                      BufferStatic,
                      BufferDynamic
                      );

As a side note, Ryan: if you need to interoperate with other languages, using
enums is dangerous. FPC has different enum storage semantics from most other
compilers, and will happily drop you into "undefined" behaviour.
Example from C# syntax:
   enum Day : byte {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri};
is _not_ translated as
   {$PACKENUM 1}
   Day = (Sat=1, Sun, Mon, Tue, Wed, Thu, Fri);
Instead, write
   {$PACKENUM 1}
   Day = (_low=low(Byte), Sat=1, Sun, Mon, Tue, Wed, Thu, Fri, _hi=high(Byte));


Regards,
Martok




More information about the fpc-pascal mailing list