I know that its possible to make enums that use signed or unsigned 64, 32, 16, and 8 bit values as their underlying valud type using (:ulong, :uint, :ushort, :byte). But is it possible to create a 4 bit enum?
(I'm writing some code tha开发者_如何转开发t will interop with C++ and the struct that I have in C# for a return type has one field that would be most natural as a 4-bit struct.)
From the C# spec:
The approved types for an enum are
byte
,sbyte
,short
,ushort
,int
,uint
,long
, orulong
.
None of these are 4-bit types. You'd have the same problem on the C++ side as well.
But is it possible to create a 4 bit enum?
No, mostly because that would be awkward and slow. And syntactically there exists no 4-bit type to specify as base type.
with C++ and the struct that I have in C# for a return type has one field that would be most natural as a 4-bit struct.
I doubt that very much, C++ can deal with bit fields but this is very efficient (except maybe in space).
Interop with C++ is difficult enough, when the return-type is your choice then don't make it any harder than it has to be.
精彩评论