Fixed typedef reuse

This commit is contained in:
Pavel Kirienko
2014-04-19 15:52:17 +04:00
parent 2eb15268f7
commit c4c77ea321
3 changed files with 14 additions and 10 deletions
@@ -50,10 +50,12 @@ public:
static typename IntegerSpec<BitLen, SignednessUnsigned, CastModeTruncate>::StorageType static typename IntegerSpec<BitLen, SignednessUnsigned, CastModeTruncate>::StorageType
toIeee(typename NativeFloatSelector<BitLen>::Type value) toIeee(typename NativeFloatSelector<BitLen>::Type value)
{ {
typedef typename IntegerSpec<BitLen, SignednessUnsigned, CastModeTruncate>::StorageType IntType; union
typedef typename NativeFloatSelector<BitLen>::Type FloatType; {
StaticAssert<sizeof(FloatType) * 8 == BitLen>::check(); typename IntegerSpec<BitLen, SignednessUnsigned, CastModeTruncate>::StorageType i;
union { IntType i; FloatType f; } u; typename NativeFloatSelector<BitLen>::Type f;
} u;
StaticAssert<sizeof(u.f) * 8 == BitLen>::check();
u.f = value; u.f = value;
return u.i; return u.i;
} }
@@ -62,10 +64,12 @@ public:
static typename NativeFloatSelector<BitLen>::Type static typename NativeFloatSelector<BitLen>::Type
toNative(typename IntegerSpec<BitLen, SignednessUnsigned, CastModeTruncate>::StorageType value) toNative(typename IntegerSpec<BitLen, SignednessUnsigned, CastModeTruncate>::StorageType value)
{ {
typedef typename IntegerSpec<BitLen, SignednessUnsigned, CastModeTruncate>::StorageType IntType; union
typedef typename NativeFloatSelector<BitLen>::Type FloatType; {
StaticAssert<sizeof(FloatType) * 8 == BitLen>::check(); typename IntegerSpec<BitLen, SignednessUnsigned, CastModeTruncate>::StorageType i;
union { IntType i; FloatType f; } u; typename NativeFloatSelector<BitLen>::Type f;
} u;
StaticAssert<sizeof(u.f) * 8 == BitLen>::check();
u.i = value; u.i = value;
return u.f; return u.f;
} }
@@ -142,7 +142,7 @@ GlobalDataTypeRegistry::RegistResult GlobalDataTypeRegistry::regist(DataTypeID i
return RegistResultFrozen; return RegistResultFrozen;
} }
static union EntryUnion static union
{ {
uint8_t buffer[sizeof(Entry)]; uint8_t buffer[sizeof(Entry)];
long long _aligner_1; long long _aligner_1;
@@ -70,7 +70,7 @@ public:
virtual uavcan::MonotonicTime getMonotonic() const virtual uavcan::MonotonicTime getMonotonic() const
{ {
struct timespec ts; timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
{ {
throw Exception("Failed to get monotonic time"); throw Exception("Failed to get monotonic time");