#include <stdint.h>
#include <cstdio>
union DWord
{
DWord() : dword(0)
{}
DWord(uint32_t valor) : dword(valor)
{}
void operator=(uint32_t valor) { dword = valor; }
uint32_t dword;
struct
{
uint32_t valor;
};
struct
{
uint16_t word0;
uint16_t word1;
};
struct
{
uint8_t byte0;
uint8_t byte1;
uint8_t byte2;
uint8_t byte3;
};
};
int main()
{
DWord a = 700;
printf("O valor no inteiro: %d\n", a.valor);
printf("O valor no bytes 0: %d\n", a.byte0);
printf("O valor no bytes 1: %d\n", a.byte1);
// O contrĂ¡rio:
DWord b;
b.byte0 = 188;
b.byte1 = 2;
printf("O valor no inteiro: %d\n", b.valor);
return 0;
}
I2luY2x1ZGUgPHN0ZGludC5oPgojaW5jbHVkZSA8Y3N0ZGlvPgoKdW5pb24gRFdvcmQKewoJRFdvcmQoKSA6IGR3b3JkKDApCgl7fQoKCURXb3JkKHVpbnQzMl90IHZhbG9yKSA6IGR3b3JkKHZhbG9yKQoJe30KCgl2b2lkIG9wZXJhdG9yPSh1aW50MzJfdCB2YWxvcikgeyBkd29yZCA9IHZhbG9yOyB9CgoJdWludDMyX3QgZHdvcmQ7CgoJc3RydWN0Cgl7CgkJdWludDMyX3QgdmFsb3I7Cgl9OwoKCXN0cnVjdAoJewoJCXVpbnQxNl90IHdvcmQwOwoJCXVpbnQxNl90IHdvcmQxOwoJfTsKCglzdHJ1Y3QKCXsKCQl1aW50OF90IGJ5dGUwOwoJCXVpbnQ4X3QgYnl0ZTE7CgkJdWludDhfdCBieXRlMjsKCQl1aW50OF90IGJ5dGUzOwoJfTsKfTsKCmludCBtYWluKCkKewoJRFdvcmQgYSA9IDcwMDsKCglwcmludGYoIk8gdmFsb3Igbm8gaW50ZWlybzogJWRcbiIsIGEudmFsb3IpOwoJcHJpbnRmKCJPIHZhbG9yIG5vIGJ5dGVzIDA6ICVkXG4iLCBhLmJ5dGUwKTsKCXByaW50ZigiTyB2YWxvciBubyBieXRlcyAxOiAlZFxuIiwgYS5ieXRlMSk7CgoJLy8gTyBjb250csOhcmlvOgoKCURXb3JkIGI7CgoJYi5ieXRlMCA9IDE4ODsKCWIuYnl0ZTEgPSAyOwoKCXByaW50ZigiTyB2YWxvciBubyBpbnRlaXJvOiAlZFxuIiwgYi52YWxvcik7CgoJcmV0dXJuIDA7Cn0KCg==