I am programming en Visual C++ .NET. I have an unsigned char array, and I need to cast it to a struct that I created. The struct I defined is the following:
struct datagramaIP {
unsigned int longCabecera:4;
unsigned int version:4;
unsigned int tipoServicio:8;
unsigned int longTotal:16;
unsigned int idFragmento:16;
unsigned int despFragmento:13;
unsigned int fragmentosAdicionales:1;
unsigned int noFragmentar:1;
unsigned int reservado:1;
unsigned int TTL:8;
unsigned int protocolo:8;
unsigned int checksumCabecera:16;
unsigned char dirIPFuente[4];
unsigned char dirIPDest[4];
unsigned char *opciones;
unsigned char *datos;
};
And I defined a variable like this:
unsigned char datagrama __gc[] = new unsigned char __gc[1500];
I need to store the contents in datagrama in a variable of the struct I defined above. How I can do it?
I tried do that with static_cast in the following manner:
struct datagramaIP *ip = static_cast<struct datagramaIP *>(datagrama);
but it gives me an error in compilation time. The error is:
error C2440: 'static_cast' : no se puede realizar la conversión de 'unsigned char __gc[]' a 'datagramaIP *'
struct datagramaIP {
unsigned int longCabecera:4;
unsigned int version:4;
unsigned int tipoServicio:8;
unsigned int longTotal:16;
unsigned int idFragmento:16;
unsigned int despFragmento:13;
unsigned int fragmentosAdicionales:1;
unsigned int noFragmentar:1;
unsigned int reservado:1;
unsigned int TTL:8;
unsigned int protocolo:8;
unsigned int checksumCabecera:16;
unsigned char dirIPFuente[4];
unsigned char dirIPDest[4];
unsigned char *opciones;
unsigned char *datos;
};
And I defined a variable like this:
unsigned char datagrama __gc[] = new unsigned char __gc[1500];
I need to store the contents in datagrama in a variable of the struct I defined above. How I can do it?
I tried do that with static_cast in the following manner:
struct datagramaIP *ip = static_cast<struct datagramaIP *>(datagrama);
but it gives me an error in compilation time. The error is:
error C2440: 'static_cast' : no se puede realizar la conversión de 'unsigned char __gc[]' a 'datagramaIP *'