[fpc-devel] How to convert set to integer and vice versay
Gennady Agranov
gennadyagranov at gmail.com
Tue Jul 22 22:51:00 CEST 2014
Thanks again!
I am all set now - I needed {$PACKSET 4} :)
Thanks,
Gennady
program setcast;
{$ifdef FPC}
{$mode delphi}
{$PACKSET 4}
{$else}
{$APPTYPE CONSOLE}
{$endif}
uses
SysUtils;
type tenum=0..32;
tmyset= set of tenum;
var x:int64;
y:tmyset;
begin
x:=int64(y);
end.
On Tue, Jul 22, 2014 at 4:35 PM, Gennady Agranov <gennadyagranov at gmail.com>
wrote:
> 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/9b8d3c16/attachment.html>
More information about the fpc-devel
mailing list