I tried the C:\nburn\examples\mod5270\time, example. After compiling i got 3 warnings
in the function below the warning is "dereferencing type-punned pointer will break strict-aliasing rules"
/* Get the most significat DWORD of a long long usually the seconds in an NTP long long */
DWORD GetMsb( unsigned long long lv )
{
return *( ( ( PDWORD ) & lv ) );
}
What would be the corrected function?
MOD5270 Time Example, has some compile warnings
Re: MOD5270 Time Example, has some compile warnings
You could Probably do
DWORD GetMsb( unsigned long long lv )
{
return (DWORD) (lv>>32);
}
Calls library function and is slower.
Paul
DWORD GetMsb( unsigned long long lv )
{
return (DWORD) (lv>>32);
}
Calls library function and is slower.
Paul
Re: MOD5270 Time Example, has some compile warnings
If you just want to get rid of the warning you can add -fno-strict-aliasing to the c++ compiler command line for the project.
The corrected function (which belongs in a utility class in a static library) is IMO:
The test code would look like this
The corrected function (which belongs in a utility class in a static library) is IMO:
Code: Select all
enum WhichBigEndianWord{LowerBigEndian, UpperBigEndian};
uint32_t GetWord32From64( uint64_t value, WhichBigEndianWord whichWord )
{
union
{
uint64_t value64;
uint32_t word32[2];
} union_64_32;
union_64_32.value64 = value;
return union_64_32.word32[whichWord];
}
Code: Select all
uint64_t value_64bit = 0x100000008LL;
uint32_t high_32 = GetWord32From64(value_64bit,UpperBigEndian);
uint32_t low_32 = GetWord32From64(value_64bit,LowerBigEndian);
cout << "High:" <<high_32 <<endl;
cout << "Low:" << low_32 << endl;
High:1
Low:8
Re: MOD5270 Time Example, has some compile warnings
Thanks guys, its more of a heads up for NB to fix the example.