Detecting and reporting typed errors ... What does it do?

I read about how to make code more portable using fixed-width integers. I found this article that helped explain things, and in the end suggests using this anonymous union to detect and report typedef errors:

static union
{
    char   int8_t_incorrect[sizeof(  int8_t) == 1];
    char  uint8_t_incorrect[sizeof( uint8_t) == 1];
    char  int16_t_incorrect[sizeof( int16_t) == 2];
    char uint16_t_incorrect[sizeof(uint16_t) == 2];
    char  int32_t_incorrect[sizeof( int32_t) == 4];
    char uint32_t_incorrect[sizeof(uint32_t) == 4];
};

I got a little lost, and I was hoping someone could explain what this was doing?

+5
source share
2 answers

He is abusing the compiler, what he is doing.

sizeof(type) == num , 0, 1 (false true). 0 ( ), , .

, , , , typedefs (, autoconf ).

+4

- false, 0, .

+4

All Articles