[fpc-devel] How to convert set to integer and vice versay

Gennady Agranov gennadyagranov at gmail.com
Tue Jul 22 22:35:11 CEST 2014


Thanks!

Your example does compile, but if you replace 31 with 32 - it will not
compile - no matter what you use - integer, int64 or qword

And I guess I know the reason now - sizeof(left) should be equal to
sizeof(right) and 33 bits enum has sizeof of 5 :(

Any suggestions?

Thanks,
Gennady



On Tue, Jul 22, 2014 at 12:13 PM, Marco van de Voort <marcov at stack.nl>
wrote:

> In our previous episode, Gennady Agranov said:
> > >
> > > Good. And afaik in Delphi mode this works too in FPC? Did you test?
> > >
> >
> > casting integer to set does not compile in FPC - and yes - I use Delphi
> > mode :(
>
> program setcast;
>
> {$ifdef FPC}
> {$mode delphi}
> {$else}
> {$APPTYPE CONSOLE}
> {$endif}
>
> uses
>   SysUtils;
>
> type tenum=0..31;
>      tmyset= set of tenum;
>
> var x:integer;
>     y:tmyset;
>
> begin
>   x:=integer(y);
> end.
>
> compiles in both FPC (both 2.6.x and trunk) and Delphi (XE4)
>
> _______________________________________________
> 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/20140722/a4740fd0/attachment.html>


More information about the fpc-devel mailing list