1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-09-08 14:17:06 +03:00

0024537: GCC compiler warnings in byte order reversion code

Eliminate warnings in byte order inversion functionality by using unions.
Add test case simulating conversion to big endian.
This commit is contained in:
rkv
2015-09-24 14:17:41 +03:00
committed by kgv
parent 81b47143f1
commit 10a4116e31
6 changed files with 441 additions and 134 deletions

View File

@@ -32,108 +32,4 @@ struct FSD_FileHeader {
Standard_Integer edata;
};
#ifndef DO_INVERSE
#if defined ( SOLARIS ) || defined ( IRIX )
#define DO_INVERSE 1
#else
#define DO_INVERSE 0
#endif
#endif
//=======================================================================
//function : InverseInt
//purpose : Inverses bytes in the word
//=======================================================================
inline Standard_Integer InverseInt (const Standard_Integer theValue)
{
return (0 | (( theValue & 0x000000ff ) << 24 )
| (( theValue & 0x0000ff00 ) << 8 )
| (( theValue & 0x00ff0000 ) >> 8 )
| (( theValue >> 24 ) & 0x000000ff ) );
}
//=======================================================================
//function : InverseLong
//purpose : Inverses bytes in the long word
//=======================================================================
inline long InverseLong (const long theValue)
{
return (long) InverseInt ((Standard_Integer) theValue);
}
//=======================================================================
//function : InverseExtChar
//purpose : Inverses bytes in the extended character
//=======================================================================
inline Standard_ExtCharacter InverseExtChar (const Standard_ExtCharacter theValue)
{
return (0 | (( theValue & 0x00ff ) << 8 )
| (( theValue & 0xff00 ) >> 8 ) );
}
//=======================================================================
//function : InverseReal
//purpose : Inverses bytes in the real value
//=======================================================================
inline Standard_Real InverseReal (const Standard_Real theValue)
{
Standard_Real aResult;
Standard_Integer *i = (Standard_Integer*) &theValue;
Standard_Integer *j = (Standard_Integer*) &aResult;
j[1] = InverseInt (i[0]);
j[0] = InverseInt (i[1]);
return aResult;
}
//=======================================================================
//function : InverseShortReal
//purpose : Inverses bytes in the short real value
//=======================================================================
inline Standard_ShortReal InverseShortReal (const Standard_ShortReal theValue)
{
Standard_ShortReal aResult;
Standard_Integer *i = (Standard_Integer*) &aResult;
*i = InverseInt (*(Standard_Integer*) &theValue);
return aResult;
}
//=======================================================================
//function : InverseSize
//purpose : Inverses bytes in size_t type instance
//=======================================================================
template<int size>
inline Standard_Size InverseSizeSpecialized (const Standard_Size theValue, int);
template<>
inline Standard_Size InverseSizeSpecialized <4> (const Standard_Size theValue, int)
{
return (0 | (( theValue & 0x000000ff ) << 24 )
| (( theValue & 0x0000ff00 ) << 8 )
| (( theValue & 0x00ff0000 ) >> 8 )
| (( theValue >> 24 ) & 0x000000ff ) );
}
template<>
inline Standard_Size InverseSizeSpecialized <8> (const Standard_Size theValue, int)
{
Standard_Size aResult;
Standard_Integer *i = (Standard_Integer*) &theValue;
Standard_Integer *j = (Standard_Integer*) &aResult;
j[1] = InverseInt (i[0]);
j[0] = InverseInt (i[1]);
return aResult;
}
inline Standard_Size InverseSize (const Standard_Size theValue)
{
return InverseSizeSpecialized <sizeof(Standard_Size)> (theValue, 0);
}
#endif