Flags w/ long enum

Is it possible to use the {Flags} attribute with a long enum in order to have more than 31 flags?

I have a case where I need more than 31 flags. I modified the enum from int to long as shown in the frag below in order to be able to create a 63 bit bitfield. Code compiles and runs but the property no longer operates as a bitfield in the TAP GUI. Rather than being able to select any combination of flags using checkboxes, the checkboxes are gone and the GUI allows the operator to choose just a single value.

[Flags]
public enum bitfieldFlags : long //create 63 bit bitmap
{ bit0 = 0x01, bit1 = 0x02, bit2 = 0x04, … bit57 = 0X0400000000000000
}

Thanks
jim

Hi Jim,

For me this seems to work, the problem may be that you need to put a L on the end of 0x04…00L,. Also, if you want 64 values you should be able to use ulong as the enum type.

Try this for example:

        public enum FlaggedEnum64 : ulong
        {
            Bit01 = 0x0000_0000_0000_0001L,
            Bit02 = 0x0000_0000_0000_0002L,
            Bit03 = 0x0000_0000_0000_0004L,
            Bit04 = 0x0000_0000_0000_0008L,
            Bit05 = 0x0000_0000_0000_0010L,
            Bit06 = 0x0000_0000_0000_0020L,
            Bit07 = 0x0000_0000_0000_0040L,
            Bit08 = 0x0000_0000_0000_0080L,
            Bit09 = 0x0000_0000_0000_0100L,
            Bit10 = 0x0000_0000_0000_0200L,
            Bit11 = 0x0000_0000_0000_0400L,
            Bit12 = 0x0000_0000_0000_0800L,
            Bit13 = 0x0000_0000_0000_1000L,
            Bit14 = 0x0000_0000_0000_2000L,
            Bit15 = 0x0000_0000_0000_4000L,
            Bit16 = 0x0000_0000_0000_8000L,
            Bit17 = 0x0000_0000_0001_0000L,
            Bit18 = 0x0000_0000_0002_0000L,
            Bit19 = 0x0000_0000_0004_0000L,
            Bit20 = 0x0000_0000_0008_0000L,
            Bit21 = 0x0000_0000_0010_0000L,
            Bit22 = 0x0000_0000_0020_0000L,
            Bit23 = 0x0000_0000_0040_0000L,
            Bit24 = 0x0000_0000_0080_0000L,
            Bit25 = 0x0000_0000_0100_0000L,
            Bit26 = 0x0000_0000_0200_0000L,
            Bit27 = 0x0000_0000_0400_0000L,
            Bit28 = 0x0000_0000_0800_0000L,
            Bit29 = 0x0000_0000_1000_0000L,
            Bit30 = 0x0000_0000_2000_0000L,
            Bit31 = 0x0000_0000_4000_0000L,
            Bit32 = 0x0000_0000_8000_0000L,
            Bit33 = 0x0000_0001_0000_0000L,
            Bit34 = 0x0000_0002_0000_0000L,
            Bit35 = 0x0000_0004_0000_0000L,
            Bit36 = 0x0000_0008_0000_0000L,
            Bit37 = 0x0000_0010_0000_0000L,
            Bit38 = 0x0000_0020_0000_0000L,
            Bit39 = 0x0000_0040_0000_0000L,
            Bit40 = 0x0000_0080_0000_0000L,
            Bit41 = 0x0000_0100_0000_0000L,
            Bit42 = 0x0000_0200_0000_0000L,
            Bit43 = 0x0000_0400_0000_0000L,
            Bit44 = 0x0000_0800_0000_0000L,
            Bit45 = 0x0000_1000_0000_0000L,
            Bit46 = 0x0000_2000_0000_0000L,
            Bit47 = 0x0000_4000_0000_0000L,
            Bit48 = 0x0000_8000_0000_0000L,
            Bit49 = 0x0001_0000_0000_0000L,
            Bit50 = 0x0002_0000_0000_0000L,
            Bit51 = 0x0004_0000_0000_0000L,
            Bit52 = 0x0008_0000_0000_0000L,
            Bit53 = 0x0010_0000_0000_0000L,
            Bit54 = 0x0020_0000_0000_0000L,
            Bit55 = 0x0040_0000_0000_0000L,
            Bit56 = 0x0080_0000_0000_0000L,
            Bit57 = 0x0100_0000_0000_0000L,
            Bit58 = 0x0200_0000_0000_0000L,
            Bit59 = 0x0400_0000_0000_0000L,
            Bit60 = 0x0800_0000_0000_0000L,
            Bit61 = 0x1000_0000_0000_0000L,
            Bit62 = 0x2000_0000_0000_0000L,
            Bit63 = 0x4000_0000_0000_0000L,
            Bit64 = 0x8000_0000_0000_0000L,
        }
2 Likes

Thanks for reply Rolf.

Adding the “L” does not change the behavior for me. The TAP GUI still does not recognize as a bitfield when enum is long or ulong. This is an older program that I’m running form TAP8 so perhaps that’s why.

I worked around this problems but splitting the bitfields into two 32 bit properties and then combining the two bitfields into a single 64 bit bitfield at runtime.

Thanks!

1 Like

@jim.ogden I think the old version is likely why you are seeing a difference but glad you found a workaround. Are you planning to update at some point?

Oh you noticed that huh Brennen. Was hoping you didn’t :blush:.

I’m a bit embarrassed because I did port all of old code to the latest TAP and had it all built and mostly working but had some minor problems that I just didn’t have time to cope with so reverted to using my old code when the pressure was on.

I am doing all my new development on the latest TAP. Will try to move all the old stuff to latest version when I can find the time.

BTW Congrats on the OpenTap Forum. I love it. Don’t contribute much (so far) but am always lurking …

1 Like

@jim.ogden great! I’m glad you found it. I know you were hoping to see if created a while back when you first started using OpenTAP.

When you get back to migrating let us know and we can help out, but I’m glad at least the new development is on OpenTAP :smiley: