Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-10

Sets

7 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Juha Manninen

If I have have a set with < 9 elements, like :

type
TMyEnum = (
xOne,
xTwo,
xThree,
xFour,
xFive

  );
  // Count <= 8, fits in one Byte
  TMyEnums = set of TMyEnum;

then in Delphi a variable of that type can be casted to Byte. Other casts don't work.
In FPC I must cast it to Integer!
Does it really mean that all sets in FPC reserve at least 32 bits? Is it documented? I did not find it as "Set" gives so many false matches.

I hope the implementation is otherwise compatible with Delphi, meaning that the bits start from LSB always. I rely now on this implementation detail. There is code that transfers bitfields between computers. Using type checking and descriptive names makes the code better in many ways, compared to using integers & AND operator.

Juha

Peter
to Juha Manninen

Perhaps you need the {$PACKENUM n} compiler directive for the enumerated type?

Juha Manninen wrote 30 lines
If I have have a set with < 9 elements, like : type TMyEnum = ( xOne, xTwo, xThree, xFour, xFive ); // Count <= 8, fits in one Byte TMyEnums = set of TMyEnum; then in Delphi a variable of that type can be casted to Byte. Other casts don't work. In FPC I must cast it to Integer! Does it really mean that all sets in FPC reserve at least 32 bits? Is it documented? I did not find it as "Set" gives so many false matches. I hope the implementation is otherwise compatible with Delphi, meaning that the bits start from LSB always. I rely now on this implementation detail. There is code that transfers bitfields between computers. Using type checking and descriptive names makes the code better in many ways, compared to using integers & AND operator. Juha _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Sven Barth
to Juha Manninen: If I have have a set with < 9 elements, like : type TMyEnum = ( xFive ); // Count <= 8,…
Juha Manninen wrote 18 lines
If I have have a set with < 9 elements, like : type TMyEnum = ( xOne, xTwo, xThree, xFour, xFive ); // Count <= 8, fits in one Byte TMyEnums = set of TMyEnum; then in Delphi a variable of that type can be casted to Byte. Other casts don't work. In FPC I must cast it to Integer! Does it really mean that all sets in FPC reserve at least 32 bits? Is it documented? I did not find it as "Set" gives so many false matches.

It's documented in the language reference guide:
http://freepascal.org/docs-html/ref/refsu20.html#x44-510003.3.3

And as Peter already mentioned there is $PACKSET:
http://freepascal.org/docs-html/prog/progsu61.html#x67-660001.1.61

Regards,
Sven

Marco van de Voort
to Juha Manninen: If I have have a set with < 9 elements, like : type TMyEnum = ( xFive ); // Count <= 8,…

In our previous episode, Juha Manninen said:
[ Charset ISO-8859-1 unsupported, converting... ]

Show quoted text 16 lines
If I have have a set with < 9 elements, like : type TMyEnum = ( xOne, xTwo, xThree, xFour, xFive ); // Count <= 8, fits in one Byte TMyEnums = set of TMyEnum; then in Delphi a variable of that type can be casted to Byte. Other casts don't work. In FPC I must cast it to Integer!

Workse fine here:

{$mode delphi}
type
TMyEnum = (
xOne,
xTwo,
xThree,
xFour,
xFive

  );
  // Count <= 8, fits in one Byte
  TMyEnums = set of TMyEnum;
var x :TMyenums;
    y : byte;
begin
 y:=byte(x);
end.

Hint: if you want delphi compatibility, use {$mode delphi} :-)

Juha Manninen
to Jonas Maebe
Jonas Maebe wrote

Ok, sorry Marco and Jonas.
This unit did not have Mode Delphi. I thought the setting in a Lazarus project was enough but no. This unit is not part of the project but is used by it.
This is a big code base I must learn. Some units must compile with Delphi and FPC, some units only with Delphi.
It is better to put :
{$IFDEF FPC}

   {$MODE Delphi}

{$ENDIF}

in every unit.

Thanks and regards,
Juha