Get rid of some old c style casts

This commit is contained in:
Jan Möbius
2023-08-23 10:16:01 +02:00
parent 931368f0ba
commit 38e5a2313b

View File

@@ -74,7 +74,7 @@ namespace IO {
short int read_short(FILE* _in, bool _swap) short int read_short(FILE* _in, bool _swap)
{ {
union u1 { short int s; unsigned char c[2]; } sc; union u1 { short int s; unsigned char c[2]; } sc;
fread((char*)sc.c, 1, 2, _in); fread(reinterpret_cast<char*>(sc.c), 1, 2, _in);
if (_swap) std::swap(sc.c[0], sc.c[1]); if (_swap) std::swap(sc.c[0], sc.c[1]);
return sc.s; return sc.s;
} }
@@ -86,7 +86,7 @@ short int read_short(FILE* _in, bool _swap)
int read_int(FILE* _in, bool _swap) int read_int(FILE* _in, bool _swap)
{ {
union u2 { int i; unsigned char c[4]; } ic; union u2 { int i; unsigned char c[4]; } ic;
fread((char*)ic.c, 1, 4, _in); fread(reinterpret_cast<char*>(ic.c), 1, 4, _in);
if (_swap) { if (_swap) {
std::swap(ic.c[0], ic.c[3]); std::swap(ic.c[0], ic.c[3]);
std::swap(ic.c[1], ic.c[2]); std::swap(ic.c[1], ic.c[2]);
@@ -101,7 +101,7 @@ int read_int(FILE* _in, bool _swap)
float read_float(FILE* _in, bool _swap) float read_float(FILE* _in, bool _swap)
{ {
union u3 { float f; unsigned char c[4]; } fc; union u3 { float f; unsigned char c[4]; } fc;
fread((char*)fc.c, 1, 4, _in); fread(reinterpret_cast<char*>(fc.c), 1, 4, _in);
if (_swap) { if (_swap) {
std::swap(fc.c[0], fc.c[3]); std::swap(fc.c[0], fc.c[3]);
std::swap(fc.c[1], fc.c[2]); std::swap(fc.c[1], fc.c[2]);
@@ -116,7 +116,7 @@ float read_float(FILE* _in, bool _swap)
double read_double(FILE* _in, bool _swap) double read_double(FILE* _in, bool _swap)
{ {
union u4 { double d; unsigned char c[8]; } dc; union u4 { double d; unsigned char c[8]; } dc;
fread((char*)dc.c, 1, 8, _in); fread(reinterpret_cast<char*>(dc.c), 1, 8, _in);
if (_swap) { if (_swap) {
std::swap(dc.c[0], dc.c[7]); std::swap(dc.c[0], dc.c[7]);
std::swap(dc.c[1], dc.c[6]); std::swap(dc.c[1], dc.c[6]);
@@ -131,7 +131,7 @@ double read_double(FILE* _in, bool _swap)
short int read_short(std::istream& _in, bool _swap) short int read_short(std::istream& _in, bool _swap)
{ {
union u1 { short int s; unsigned char c[2]; } sc; union u1 { short int s; unsigned char c[2]; } sc;
_in.read((char*)sc.c, 2); _in.read(reinterpret_cast<char*>(sc.c), 2);
if (_swap) std::swap(sc.c[0], sc.c[1]); if (_swap) std::swap(sc.c[0], sc.c[1]);
return sc.s; return sc.s;
} }
@@ -143,7 +143,7 @@ short int read_short(std::istream& _in, bool _swap)
int read_int(std::istream& _in, bool _swap) int read_int(std::istream& _in, bool _swap)
{ {
union u2 { int i; unsigned char c[4]; } ic; union u2 { int i; unsigned char c[4]; } ic;
_in.read((char*)ic.c, 4); _in.read(reinterpret_cast<char*>(ic.c), 4);
if (_swap) { if (_swap) {
std::swap(ic.c[0], ic.c[3]); std::swap(ic.c[0], ic.c[3]);
std::swap(ic.c[1], ic.c[2]); std::swap(ic.c[1], ic.c[2]);
@@ -158,7 +158,7 @@ int read_int(std::istream& _in, bool _swap)
float read_float(std::istream& _in, bool _swap) float read_float(std::istream& _in, bool _swap)
{ {
union u3 { float f; unsigned char c[4]; } fc; union u3 { float f; unsigned char c[4]; } fc;
_in.read((char*)fc.c, 4); _in.read(reinterpret_cast<char*>(fc.c), 4);
if (_swap) { if (_swap) {
std::swap(fc.c[0], fc.c[3]); std::swap(fc.c[0], fc.c[3]);
std::swap(fc.c[1], fc.c[2]); std::swap(fc.c[1], fc.c[2]);
@@ -173,7 +173,7 @@ float read_float(std::istream& _in, bool _swap)
double read_double(std::istream& _in, bool _swap) double read_double(std::istream& _in, bool _swap)
{ {
union u4 { double d; unsigned char c[8]; } dc; union u4 { double d; unsigned char c[8]; } dc;
_in.read((char*)dc.c, 8); _in.read(reinterpret_cast<char*>(dc.c), 8);
if (_swap) { if (_swap) {
std::swap(dc.c[0], dc.c[7]); std::swap(dc.c[0], dc.c[7]);
std::swap(dc.c[1], dc.c[6]); std::swap(dc.c[1], dc.c[6]);
@@ -192,7 +192,7 @@ void write_short(short int _i, FILE* _out, bool _swap)
union u1 { short int s; unsigned char c[2]; } sc; union u1 { short int s; unsigned char c[2]; } sc;
sc.s = _i; sc.s = _i;
if (_swap) std::swap(sc.c[0], sc.c[1]); if (_swap) std::swap(sc.c[0], sc.c[1]);
fwrite((char*)sc.c, 1, 2, _out); fwrite(reinterpret_cast<char*>(sc.c), 1, 2, _out);
} }
@@ -207,7 +207,7 @@ void write_int(int _i, FILE* _out, bool _swap)
std::swap(ic.c[0], ic.c[3]); std::swap(ic.c[0], ic.c[3]);
std::swap(ic.c[1], ic.c[2]); std::swap(ic.c[1], ic.c[2]);
} }
fwrite((char*)ic.c, 1, 4, _out); fwrite(reinterpret_cast<char*>(ic.c), 1, 4, _out);
} }
@@ -222,7 +222,7 @@ void write_float(float _f, FILE* _out, bool _swap)
std::swap(fc.c[0], fc.c[3]); std::swap(fc.c[0], fc.c[3]);
std::swap(fc.c[1], fc.c[2]); std::swap(fc.c[1], fc.c[2]);
} }
fwrite((char*)fc.c, 1, 4, _out); fwrite(reinterpret_cast<char*>(fc.c), 1, 4, _out);
} }
@@ -239,7 +239,7 @@ void write_double(double _d, FILE* _out, bool _swap)
std::swap(dc.c[2], dc.c[5]); std::swap(dc.c[2], dc.c[5]);
std::swap(dc.c[3], dc.c[4]); std::swap(dc.c[3], dc.c[4]);
} }
fwrite((char*)dc.c, 1, 8, _out); fwrite(reinterpret_cast<char*>(dc.c), 1, 8, _out);
} }
@@ -251,7 +251,7 @@ void write_short(short int _i, std::ostream& _out, bool _swap)
union u1 { short int s; unsigned char c[2]; } sc; union u1 { short int s; unsigned char c[2]; } sc;
sc.s = _i; sc.s = _i;
if (_swap) std::swap(sc.c[0], sc.c[1]); if (_swap) std::swap(sc.c[0], sc.c[1]);
_out.write((char*)sc.c, 2); _out.write(reinterpret_cast<char*>(sc.c), 2);
} }
@@ -266,7 +266,7 @@ void write_int(int _i, std::ostream& _out, bool _swap)
std::swap(ic.c[0], ic.c[3]); std::swap(ic.c[0], ic.c[3]);
std::swap(ic.c[1], ic.c[2]); std::swap(ic.c[1], ic.c[2]);
} }
_out.write((char*)ic.c, 4); _out.write(reinterpret_cast<char*>(ic.c), 4);
} }
@@ -281,7 +281,7 @@ void write_float(float _f, std::ostream& _out, bool _swap)
std::swap(fc.c[0], fc.c[3]); std::swap(fc.c[0], fc.c[3]);
std::swap(fc.c[1], fc.c[2]); std::swap(fc.c[1], fc.c[2]);
} }
_out.write((char*)fc.c, 4); _out.write(reinterpret_cast<char*>(fc.c), 4);
} }
@@ -298,7 +298,7 @@ void write_double(double _d, std::ostream& _out, bool _swap)
std::swap(dc.c[2], dc.c[5]); std::swap(dc.c[2], dc.c[5]);
std::swap(dc.c[3], dc.c[4]); std::swap(dc.c[3], dc.c[4]);
} }
_out.write((char*)dc.c, 8); _out.write(reinterpret_cast<char*>(dc.c), 8);
} }