From: ehofman Date: Thu, 15 Sep 2005 17:06:31 +0000 (+0000) Subject: Use inttypes.h specified types. This is the standard and fixes some 64-bit problems. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b1b6abf285d0134211304efe9d9c3c7f9caea555;p=simgear.git Use inttypes.h specified types. This is the standard and fixes some 64-bit problems. --- diff --git a/simgear/io/lowlevel.cxx b/simgear/io/lowlevel.cxx index e5c40826..982cf06f 100644 --- a/simgear/io/lowlevel.cxx +++ b/simgear/io/lowlevel.cxx @@ -81,7 +81,7 @@ void sgReadDouble ( gzFile fd, double *var ) read_error = true ; } if ( sgIsBigEndian() ) { - sgEndianSwap( (uint64*)var); + sgEndianSwap( (uint64_t*)var); } } @@ -89,7 +89,7 @@ void sgReadDouble ( gzFile fd, double *var ) void sgWriteDouble ( gzFile fd, const double var ) { if ( sgIsBigEndian() ) { - sgEndianSwap( (uint64*)&var); + sgEndianSwap( (uint64_t*)&var); } if ( gzwrite ( fd, (void *)(&var), sizeof(double) ) != sizeof(double) ) { write_error = true ; @@ -143,9 +143,9 @@ void sgWriteInt ( gzFile fd, const int var ) } -void sgReadLong ( gzFile fd, long int *var ) +void sgReadLong ( gzFile fd, int32_t *var ) { - if ( gzread ( fd, var, sizeof(long int) ) != sizeof(long int) ) { + if ( gzread ( fd, var, sizeof(int32_t) ) != sizeof(int32_t) ) { read_error = true ; } if ( sgIsBigEndian() ) { @@ -154,37 +154,37 @@ void sgReadLong ( gzFile fd, long int *var ) } -void sgWriteLong ( gzFile fd, const long int var ) +void sgWriteLong ( gzFile fd, const int32_t var ) { if ( sgIsBigEndian() ) { sgEndianSwap( (unsigned int*)&var); } - if ( gzwrite ( fd, (void *)(&var), sizeof(long int) ) - != sizeof(long int) ) + if ( gzwrite ( fd, (void *)(&var), sizeof(int32_t) ) + != sizeof(int32_t) ) { write_error = true ; } } -void sgReadLongLong ( gzFile fd, int64 *var ) +void sgReadLongLong ( gzFile fd, int64_t *var ) { - if ( gzread ( fd, var, sizeof(int64) ) != sizeof(int64) ) { + if ( gzread ( fd, var, sizeof(int64_t) ) != sizeof(int64_t) ) { read_error = true ; } if ( sgIsBigEndian() ) { - sgEndianSwap( (uint64*)var); + sgEndianSwap( (uint64_t*)var); } } -void sgWriteLongLong ( gzFile fd, const int64 var ) +void sgWriteLongLong ( gzFile fd, const int64_t var ) { if ( sgIsBigEndian() ) { - sgEndianSwap( (uint64*)&var); + sgEndianSwap( (uint64_t*)&var); } - if ( gzwrite ( fd, (void *)(&var), sizeof(int64) ) - != sizeof(int64) ) + if ( gzwrite ( fd, (void *)(&var), sizeof(int64_t) ) + != sizeof(int64_t) ) { write_error = true ; } @@ -275,7 +275,7 @@ void sgReadDouble ( gzFile fd, const unsigned int n, double *var ) } if ( sgIsBigEndian() ) { for ( unsigned int i = 0; i < n; ++i ) { - sgEndianSwap( (uint64*)var++); + sgEndianSwap( (uint64_t*)var++); } } } @@ -288,7 +288,7 @@ void sgWriteDouble ( gzFile fd, const unsigned int n, const double *var ) double *ptr = swab; memcpy( swab, var, sizeof(double) * n ); for ( unsigned int i = 0; i < n; ++i ) { - sgEndianSwap( (uint64*)ptr++); + sgEndianSwap( (uint64_t*)ptr++); } var = swab; } diff --git a/simgear/io/lowlevel.hxx b/simgear/io/lowlevel.hxx index fc8398f5..04b3aba6 100644 --- a/simgear/io/lowlevel.hxx +++ b/simgear/io/lowlevel.hxx @@ -29,17 +29,12 @@ #include +#include #include #include -#ifdef _MSC_VER -typedef __int64 int64; -typedef __int64 uint64; -#else -typedef long long int64; -typedef unsigned long long uint64; -#endif +#include // Note that output is written in little endian form (and converted as // necessary for big endian machines) @@ -54,10 +49,10 @@ void sgReadUInt ( gzFile fd, unsigned int *var ) ; void sgWriteUInt ( gzFile fd, const unsigned int var ) ; void sgReadInt ( gzFile fd, int *var ) ; void sgWriteInt ( gzFile fd, const int var ) ; -void sgReadLong ( gzFile fd, long int *var ) ; -void sgWriteLong ( gzFile fd, const long int var ) ; -void sgReadLongLong ( gzFile fd, int64 *var ) ; -void sgWriteLongLong ( gzFile fd, const int64 var ) ; +void sgReadLong ( gzFile fd, int32_t *var ) ; +void sgWriteLong ( gzFile fd, const int32_t var ) ; +void sgReadLongLong ( gzFile fd, int64_t *var ) ; +void sgWriteLongLong ( gzFile fd, const int64_t var ) ; void sgReadUShort ( gzFile fd, unsigned short *var ) ; void sgWriteUShort ( gzFile fd, const unsigned short var ) ; void sgReadShort ( gzFile fd, short *var ) ; @@ -145,7 +140,7 @@ inline void sgEndianSwap(unsigned int *x) { (( *x << 24 ) & 0xFF000000 ) ; } -inline void sgEndianSwap(uint64 *x) { +inline void sgEndianSwap(uint64_t *x) { #ifndef _MSC_VER *x = (( *x >> 56 ) & 0x00000000000000FFULL ) | diff --git a/simgear/io/sg_binobj.cxx b/simgear/io/sg_binobj.cxx index 3cbe4552..6acd4d9b 100644 --- a/simgear/io/sg_binobj.cxx +++ b/simgear/io/sg_binobj.cxx @@ -403,9 +403,9 @@ bool SGBinObject::read_bin( const string& file ) { double *dptr = (double *)ptr; if ( sgIsBigEndian() ) { - sgEndianSwap( (uint64 *)&(dptr[0]) ); - sgEndianSwap( (uint64 *)&(dptr[1]) ); - sgEndianSwap( (uint64 *)&(dptr[2]) ); + sgEndianSwap( (uint64_t *)&(dptr[0]) ); + sgEndianSwap( (uint64_t *)&(dptr[1]) ); + sgEndianSwap( (uint64_t *)&(dptr[2]) ); } gbs_center = Point3D( dptr[0], dptr[1], dptr[2] ); // cout << "Center = " << gbs_center << endl; @@ -656,7 +656,7 @@ bool SGBinObject::write_bin( const string& base, const string& name, // write header magic sgWriteUInt( fp, SG_FILE_MAGIC_NUMBER ); time_t calendar_time = time(NULL); - sgWriteLong( fp, (long int)calendar_time ); + sgWriteLong( fp, (int32_t)calendar_time ); // calculate and write number of top level objects string material;