unions and /clr

P

Peteroid

I believe this is not allowed:

union comboVar
{
int i;
double d ;
};

ref class myClass
{
comboVar m_Var_1 ; // error, no unions in ref class
comboVar* m_Var_2 ; // error no pointers either
comboVar^ m_Var_3 ; // error, not these either
} ;

Is there a /clr union equivalent?

[==P==]
 
C

Carl Daniel [VC++ MVP]

Peteroid said:
I believe this is not allowed:

union comboVar
{
int i;
double d ;
};

ref class myClass
{
comboVar m_Var_1 ; // error, no unions in ref class
comboVar* m_Var_2 ; // error no pointers either
comboVar^ m_Var_3 ; // error, not these either
} ;

Is there a /clr union equivalent?

No, there is not. The CLR doesn't support unions.

-cd
 
A

Austin Ehlers

No, there is not. The CLR doesn't support unions.

-cd
Actually, you can simulate unions with explicit layouts and field
offests. Ex:

using namespace System::Runtime::InteropServices;

[StructLayout(LayoutKind::Explicit)]
value class comboVar
{
public:
[FieldOffset(0)]
int i;
[FieldOffset(0)]
double d;

};

Austin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top