Using char array inside union

前端 未结 3 2147
情歌与酒
情歌与酒 2020-12-15 01:30

I\'m able to print the address and values of ints but not the chars of the union.Why is that so

#include 

using namespace std;

union Endian         


        
3条回答
  •  误落风尘
    2020-12-15 01:49

    It's Undefined Behaviour to access field of the union with a type other than the last set one, at least in C++.

    Whilst taking an address is legal in theory, that's not what the unions are for.

提交回复
热议问题