From 66fd438fefef0c8f71d3cf9081d45251204beb2e Mon Sep 17 00:00:00 2001 From: Thomas Fischer <thomas.fischer@ufz.de> Date: Fri, 9 Jan 2015 08:54:02 +0100 Subject: [PATCH] Fix clang warnings for old style cast. --- BaseLib/FileTools.h | 2 +- BaseLib/MemWatch.cpp | 14 ++++++--- GeoLib/Grid.h | 20 +++++++++--- GeoLib/Station.h | 42 ++++++++++++++++++------- MathLib/LinAlg/Dense/DenseMatrix-impl.h | 2 +- MathLib/LinAlg/Solvers/blas.h | 12 +++---- MathLib/LinAlg/Sparse/amuxCRS.cpp | 4 +-- MathLib/sparse.h | 16 +++++----- 8 files changed, 72 insertions(+), 40 deletions(-) diff --git a/BaseLib/FileTools.h b/BaseLib/FileTools.h index 1eee53aa32d..4167a14d21b 100644 --- a/BaseLib/FileTools.h +++ b/BaseLib/FileTools.h @@ -40,7 +40,7 @@ bool IsFileExisting(const std::string &strFilename); */ template <typename T> void writeValueBinary(std::ostream &out, T const& val) { - out.write((const char*)&val, sizeof(T)); + out.write(static_cast<const char*>(&val), sizeof(T)); } template <typename T> diff --git a/BaseLib/MemWatch.cpp b/BaseLib/MemWatch.cpp index 5672751c1c6..48873f90f46 100644 --- a/BaseLib/MemWatch.cpp +++ b/BaseLib/MemWatch.cpp @@ -35,7 +35,7 @@ unsigned MemWatch::updateMemUsage () #if !defined(WIN32) && !defined(__APPLE__) std::string fname ("/proc/"); std::stringstream str_pid; - str_pid << (unsigned) getpid(); + str_pid << static_cast<unsigned> (getpid()); fname += str_pid.str(); fname += "/statm"; unsigned pages; @@ -48,13 +48,17 @@ unsigned MemWatch::updateMemUsage () } in >> pages; - _vmem_size = ((unsigned long) pages) * ((unsigned long) getpagesize()); + _vmem_size = static_cast<unsigned long>(pages) * + static_cast<unsigned long>(getpagesize()); in >> pages; - _rmem_size = ((unsigned long) pages) * ((unsigned long) getpagesize()); + _rmem_size =static_cast<unsigned long>(pages) * + static_cast<unsigned long>(getpagesize()); in >> pages; - _smem_size = ((unsigned long) pages) * ((unsigned long) getpagesize()); + _smem_size = static_cast<unsigned long>(pages) * + static_cast<unsigned long>(getpagesize()); in >> pages; - _cmem_size = ((unsigned long) pages) * ((unsigned long) getpagesize()); + _cmem_size = static_cast<unsigned long>(pages) * + static_cast<unsigned long>(getpagesize()); in.close (); #endif diff --git a/GeoLib/Grid.h b/GeoLib/Grid.h index 6ad03f52294..11a5a706f73 100644 --- a/GeoLib/Grid.h +++ b/GeoLib/Grid.h @@ -262,23 +262,33 @@ private: } else { // 1d case: dx == 0, dy == 0, dz != 0 _n_steps[0] = 1; _n_steps[1] = 1; - _n_steps[2] = static_cast<std::size_t> (ceil(n_pnts / (double) max_num_per_grid_cell)); + _n_steps[2] = static_cast<std::size_t> ( + ceil(n_pnts/static_cast<double>(max_num_per_grid_cell)) + ); } } else { // dy != 0 if(fabs(delta[2]) < eps) { // 1d case: dx == 0, dy != 0, dz == 0 _n_steps[0] = 1; - _n_steps[1] = static_cast<std::size_t> (ceil(n_pnts / (double) max_num_per_grid_cell)); + _n_steps[1] = static_cast<std::size_t> ( + ceil(n_pnts/static_cast<double>(max_num_per_grid_cell)) + ); _n_steps[2] = 1; } else { // 2d case: dx == 0, dy != 0, dz != 0 _n_steps[0] = 1; - _n_steps[1] = static_cast<std::size_t> (ceil(sqrt(n_pnts * delta[1] / (max_num_per_grid_cell * delta[2])))); - _n_steps[2] = static_cast<std::size_t> (ceil(n_pnts / (double) max_num_per_grid_cell)); + _n_steps[1] = static_cast<std::size_t> ( + ceil(sqrt(n_pnts*delta[1]/(max_num_per_grid_cell*delta[2]))) + ); + _n_steps[2] = static_cast<std::size_t> ( + ceil(n_pnts/static_cast<double>(max_num_per_grid_cell)) + ); } } } else { // dx != 0 if(fabs(delta[1]) < eps) { // dy == 0 if(fabs(delta[2]) < eps) { // 1d case: dx != 0, dy == 0, dz == 0 - _n_steps[0] = static_cast<std::size_t> (ceil(n_pnts / (double) max_num_per_grid_cell)); + _n_steps[0] = static_cast<std::size_t> ( + ceil(n_pnts/static_cast<double>(max_num_per_grid_cell)) + ); _n_steps[1] = 1; _n_steps[2] = 1; } else { // 2d case: dx != 0, dy == 0, dz != 0 diff --git a/GeoLib/Station.h b/GeoLib/Station.h index e6acb378347..deaa1730d17 100644 --- a/GeoLib/Station.h +++ b/GeoLib/Station.h @@ -168,23 +168,41 @@ protected: * \param stnObject A pointer to the station object for which the x-coordinate should be returned, usually (void*)this will work fine. * \return The x-coordinate for this station. */ - static double getX(void* stnObject) { Station* stn = (Station*)stnObject; - return (*stn)[0]; } + static double getX(void* stnObject) + { + Station const*const stn = static_cast<Station*>(stnObject); + return (*stn)[0]; + } /// Returns the y-coordinate of this station. See the detailed documentation for getX concerning the syntax. - static double getY(void* stnObject) { Station* stn = (Station*)stnObject; - return (*stn)[1]; } + static double getY(void* stnObject) + { + Station const*const stn = static_cast<Station*>(stnObject); + return (*stn)[1]; + } /// Returns the z-coordinate of this station. See the detailed documentation for getX concerning the syntax. - static double getZ(void* stnObject) { Station* stn = (Station*)stnObject; - return (*stn)[2]; } + static double getZ(void* stnObject) + { + Station* stn = static_cast<Station*>(stnObject); + return (*stn)[2]; + } /// Sets the x-coordinate for this station. See the detailed documentation for getX concerning the syntax. - static void setX(void* stnObject, double val) { Station* stn = (Station*)stnObject; - (*stn)[0] = val; } + static void setX(void* stnObject, double val) + { + Station* stn = static_cast<Station*>(stnObject); + (*stn)[0] = val; + } /// Sets the y-coordinate for this station. See the detailed documentation for getX concerning the syntax. - static void setY(void* stnObject, double val) { Station* stn = (Station*)stnObject; - (*stn)[1] = val; } + static void setY(void* stnObject, double val) + { + Station* stn = static_cast<Station*>(stnObject); + (*stn)[1] = val; + } /// Sets the z-coordinate for this station. See the detailed documentation for getX concerning the syntax. - static void setZ(void* stnObject, double val) { Station* stn = (Station*)stnObject; - (*stn)[2] = val; } + static void setZ(void* stnObject, double val) + { + Station* stn = static_cast<Station*>(stnObject); + (*stn)[2] = val; + } std::string _name; StationType _type; // GeoSys Station Type diff --git a/MathLib/LinAlg/Dense/DenseMatrix-impl.h b/MathLib/LinAlg/Dense/DenseMatrix-impl.h index 5e9e70975f5..a05dd54857a 100644 --- a/MathLib/LinAlg/Dense/DenseMatrix-impl.h +++ b/MathLib/LinAlg/Dense/DenseMatrix-impl.h @@ -289,7 +289,7 @@ template <typename FP_TYPE, typename IDX_TYPE> FP_TYPE sqrFrobNrm (const DenseMatrix<FP_TYPE, IDX_TYPE> &mat) { - FP_TYPE nrm((FP_TYPE) (0)); + FP_TYPE nrm(static_cast<FP_TYPE>(0)); IDX_TYPE i, j; for (j = 0; j < mat.getNCols(); j++) for (i = 0; i < mat.getNRows(); i++) diff --git a/MathLib/LinAlg/Solvers/blas.h b/MathLib/LinAlg/Solvers/blas.h index d4ab8365214..1e1503e10ae 100644 --- a/MathLib/LinAlg/Solvers/blas.h +++ b/MathLib/LinAlg/Solvers/blas.h @@ -293,13 +293,13 @@ namespace blas // Conv.Copy double2float inline void copy(const unsigned n, double* orig, float* dest) { - for (unsigned i=0; i<n; i++) dest[i] = (float) orig[i]; + for (unsigned i=0; i<n; i++) dest[i] = static_cast<float>(orig[i]); } // Conv.Copy float2double inline void copy(const unsigned n, float* orig, double* dest) { - for (unsigned i=0; i<n; i++) dest[i] = (double) orig[i]; + for (unsigned i=0; i<n; i++) dest[i] = static_cast<double>(orig[i]); } // Scalar product conj(x)*y @@ -1014,14 +1014,14 @@ namespace blas inline void fill0_ltr(unsigned n, double* A) { for (unsigned j=0; j<n; ++j) { - *A++ = (double) j; + *A++ = static_cast<double>(j); for (unsigned i=j+1; i<n; ++i) *A++ = D_ZERO; } } inline void fill0_ltr(unsigned n, float* A) { for (unsigned j=0; j<n; ++j) { - *A++ = (float) j; + *A++ = static_cast<float>(j); for (unsigned i=j+1; i<n; ++i) *A++ = S_ZERO; } } @@ -1070,7 +1070,7 @@ namespace blas for (unsigned i=0; i<n; ++i) { for (unsigned j=0; j<i; ++j) *A++ = D_ZERO; // for pivoting, a ltr is assumed to have ones on the diagonal - *A++ = (double) i; + *A++ = static_cast<double>(i); } } inline void fillId_ltr(unsigned n, float *A) @@ -1078,7 +1078,7 @@ namespace blas for (unsigned i=0; i<n; ++i) { for (unsigned j=0; j<i; ++j) *A++ = S_ZERO; // for pivoting, a ltr is assumed to have ones on the diagonal - *A++ = (float) i; + *A++ = static_cast<float>(i); } } diff --git a/MathLib/LinAlg/Sparse/amuxCRS.cpp b/MathLib/LinAlg/Sparse/amuxCRS.cpp index 37212e789bd..935b40b3b0b 100644 --- a/MathLib/LinAlg/Sparse/amuxCRS.cpp +++ b/MathLib/LinAlg/Sparse/amuxCRS.cpp @@ -45,7 +45,7 @@ struct MatMultThreadParam { extern "C" { void* amuxCRSpthread (void* ptr) { - MatMultThreadParam *thread_param((MatMultThreadParam*) (ptr)); + MatMultThreadParam *thread_param(static_cast<MatMultThreadParam*>(ptr)); const double a(thread_param->_a); const unsigned beg_row(thread_param->_beg_row); const unsigned end_row(thread_param->_end_row); @@ -75,7 +75,7 @@ void amuxCRSParallelPThreads (double a, #ifdef HAVE_PTHREADS // fill thread data objects MatMultThreadParam** thread_param_array (new MatMultThreadParam*[num_of_pthreads]); - double step_size ((double)(n)/(double)(num_of_pthreads)); + double step_size (static_cast<double>(n)/(num_of_pthreads)); for (unsigned k(0); k<num_of_pthreads; k++) { const unsigned beg (static_cast<unsigned>(k*step_size)); const unsigned end (static_cast<unsigned>((k+1)*step_size)); diff --git a/MathLib/sparse.h b/MathLib/sparse.h index aaf56f48c17..2b9a37cafa8 100644 --- a/MathLib/sparse.h +++ b/MathLib/sparse.h @@ -23,15 +23,15 @@ template<class T> void CS_write(std::ostream &os, unsigned n, unsigned const* iA, unsigned const* jA, T const* A) { - os.write((char*) &n, sizeof(unsigned)); - os.write((char*) iA, (n + 1) * sizeof(unsigned)); - os.write((char*) jA, iA[n] * sizeof(unsigned)); - os.write((char*) A, iA[n] * sizeof(T)); + os.write(reinterpret_cast<char*>(&n), sizeof(unsigned)); + os.write(reinterpret_cast<char*>(const_cast<unsigned*>(iA)), (n + 1) * sizeof(unsigned)); + os.write(reinterpret_cast<char*>(const_cast<unsigned*>(jA)), iA[n] * sizeof(unsigned)); + os.write(reinterpret_cast<char*>(A), iA[n] * sizeof(T)); } template<class T> void CS_read(std::istream &is, unsigned &n, unsigned* &iA, unsigned* &jA, T* &A) { - is.read((char*) &n, sizeof(unsigned)); + is.read(reinterpret_cast<char*>(&n), sizeof(unsigned)); if (iA != NULL) { delete[] iA; delete[] jA; @@ -39,15 +39,15 @@ template<class T> void CS_read(std::istream &is, unsigned &n, unsigned* &iA, uns } iA = new unsigned[n + 1]; assert(iA != NULL); - is.read((char*) iA, (n + 1) * sizeof(unsigned)); + is.read(reinterpret_cast<char*>(iA), (n + 1) * sizeof(unsigned)); jA = new unsigned[iA[n]]; assert(jA != NULL); - is.read((char*) jA, iA[n] * sizeof(unsigned)); + is.read(reinterpret_cast<char*>(jA), iA[n] * sizeof(unsigned)); A = new T[iA[n]]; assert(A != NULL); - is.read((char*) A, iA[n] * sizeof(T)); + is.read(reinterpret_cast<char*>(A), iA[n] * sizeof(T)); #ifndef NDEBUG // do simple checks -- GitLab