Clean code with typedef extraction

This commit is contained in:
Vitor Fernandes 2020-07-16 01:29:30 +01:00
parent 290e3ea85e
commit 1a0b36e390
No known key found for this signature in database
GPG key ID: EBFB4EE09F348A26

View file

@ -6,6 +6,15 @@
#include <limits.h>
#include <iostream>
typedef union {
struct
{
Int value : 31;
Int signal : 1;
} int_with_msb;
Int signed_int;
} SignedInt;
/**
* This will get the most significant bit of the Int value. If the most significant bit is 1 then the number is
* 0x11111111 --> equals to -1 integer
@ -25,15 +34,7 @@ inline Int msb(Int value)
*/
inline Int msb2(Int value)
{
typedef union {
struct
{
Int v : 31;
Int signal : 1;
} int_with_msb;
Int sint;
} SInt;
SInt sint = {.sint = value};
SignedInt sint = {.signed_int = value};
return sint.int_with_msb.signal;
};