From 1c6639f0636d2ffc3d665686756d77227c8ae6d1 Mon Sep 17 00:00:00 2001 From: Roland Schulz Date: Sun, 1 Jul 2018 21:58:10 -0700 Subject: [PATCH] Fix part of old-style casting Part clang-tidy google-readability-casting is able to do. Manual fixes in: fileio/vmdio.cpp gmxlib/nonbonded/nonbonded.cpp selection/sm_same.cpp gmxana/gmx_anadock.cpp gmxana/gmx_cluster.cpp Change-Id: Iad15ea205ac56b29f8ecaea6556fabedec975736 --- .../analysisdata/modules/displacement.cpp | 2 +- src/gromacs/commandline/filenm.cpp | 4 +- src/gromacs/commandline/pargs.cpp | 4 +- src/gromacs/correlationfunctions/autocorr.cpp | 2 +- src/gromacs/correlationfunctions/expfit.cpp | 6 +- src/gromacs/domdec/cellsizes.cpp | 8 +-- src/gromacs/domdec/domdec.cpp | 20 +++--- src/gromacs/domdec/domdec_box.cpp | 2 +- src/gromacs/domdec/domdec_setup.cpp | 10 +-- src/gromacs/essentialdynamics/edsam.cpp | 4 +- src/gromacs/ewald/pme-load-balancing.cpp | 2 +- src/gromacs/ewald/pme-redistribute.cpp | 4 +- src/gromacs/ewald/pme.cpp | 4 +- src/gromacs/fft/fft5d.cpp | 26 +++---- src/gromacs/fft/fft_fftw3.cpp | 68 +++++++++---------- src/gromacs/fft/parallel_3dfft.cpp | 4 +- src/gromacs/fileio/enxio.cpp | 10 +-- src/gromacs/fileio/espio.cpp | 2 +- src/gromacs/fileio/gmxfio-xdr.cpp | 60 ++++++++-------- src/gromacs/fileio/gmxfio.cpp | 4 +- src/gromacs/fileio/libxdrf.cpp | 10 +-- src/gromacs/fileio/matio.cpp | 4 +- src/gromacs/fileio/md5.cpp | 8 +-- src/gromacs/fileio/pdbio.cpp | 6 +- src/gromacs/fileio/tngio.cpp | 8 +-- src/gromacs/fileio/trxio.cpp | 4 +- src/gromacs/fileio/vmdio.cpp | 12 ++-- src/gromacs/fileio/writeps.cpp | 10 +-- src/gromacs/fileio/xdrd.cpp | 2 +- src/gromacs/fileio/xtcio.cpp | 2 +- src/gromacs/fileio/xvgr.cpp | 4 +- src/gromacs/gmxana/gmx_anadock.cpp | 10 +-- src/gromacs/gmxana/gmx_awh.cpp | 2 +- src/gromacs/gmxana/gmx_bar.cpp | 2 +- src/gromacs/gmxana/gmx_cluster.cpp | 4 +- src/gromacs/gmxana/gmx_density.cpp | 11 ++- src/gromacs/gmxana/gmx_dipoles.cpp | 4 +- src/gromacs/gmxana/gmx_do_dssp.cpp | 4 +- src/gromacs/gmxana/gmx_msd.cpp | 2 +- src/gromacs/gmxana/gmx_order.cpp | 2 +- src/gromacs/gmxana/gmx_trjconv.cpp | 4 +- src/gromacs/gmxana/gmx_tune_pme.cpp | 6 +- src/gromacs/gmxana/gmx_velacc.cpp | 2 +- src/gromacs/gmxana/sfactor.cpp | 30 ++++---- src/gromacs/gmxlib/nonbonded/nonbonded.cpp | 22 +++--- src/gromacs/gmxpreprocess/convparm.cpp | 16 ++--- src/gromacs/gmxpreprocess/fflibutil.cpp | 2 +- src/gromacs/gmxpreprocess/gen_ad.cpp | 14 ++-- src/gromacs/gmxpreprocess/genconf.cpp | 6 +- src/gromacs/gmxpreprocess/gmxcpp.cpp | 12 ++-- .../gmxpreprocess/gpp_bond_atomtype.cpp | 12 ++-- src/gromacs/gmxpreprocess/gpp_nextnb.cpp | 4 +- src/gromacs/gmxpreprocess/grompp.cpp | 6 +- src/gromacs/gmxpreprocess/h_db.cpp | 4 +- src/gromacs/gmxpreprocess/pdb2gmx.cpp | 2 +- src/gromacs/gmxpreprocess/pdb2top.cpp | 2 +- src/gromacs/gmxpreprocess/pgutil.cpp | 4 +- src/gromacs/gmxpreprocess/readir.cpp | 8 +-- src/gromacs/gmxpreprocess/resall.cpp | 8 +-- src/gromacs/gmxpreprocess/topdirs.cpp | 6 +- src/gromacs/gmxpreprocess/topio.cpp | 4 +- src/gromacs/gmxpreprocess/toppush.cpp | 4 +- src/gromacs/gmxpreprocess/toputil.cpp | 4 +- src/gromacs/gmxpreprocess/x2top.cpp | 2 +- src/gromacs/gmxpreprocess/xlate.cpp | 2 +- src/gromacs/imd/imd.cpp | 46 ++++++------- src/gromacs/imd/imdsocket.cpp | 8 +-- src/gromacs/listed-forces/listed-forces.cpp | 2 +- .../listed-forces/manage-threading.cpp | 4 +- src/gromacs/math/invertmatrix.cpp | 10 +-- src/gromacs/mdlib/calc_verletbuf.cpp | 6 +- src/gromacs/mdlib/calcmu.cpp | 2 +- src/gromacs/mdlib/coupling.cpp | 4 +- src/gromacs/mdlib/ebin.cpp | 2 +- src/gromacs/mdlib/expanded.cpp | 14 ++-- src/gromacs/mdlib/forcerec.cpp | 4 +- src/gromacs/mdlib/md_support.cpp | 2 +- src/gromacs/mdlib/mdebin.cpp | 2 +- src/gromacs/mdlib/mdebin_bar.cpp | 6 +- src/gromacs/mdlib/membed.cpp | 10 +-- src/gromacs/mdlib/nbnxn_atomdata.cpp | 30 ++++---- src/gromacs/mdlib/nbnxn_grid.cpp | 4 +- .../nbnxn_kernels/nbnxn_kernel_gpu_ref.cpp | 4 +- src/gromacs/mdlib/nbnxn_search.cpp | 50 +++++++------- src/gromacs/mdlib/ns.cpp | 6 +- src/gromacs/mdlib/nsgrid.cpp | 6 +- src/gromacs/mdlib/qmmm.cpp | 6 +- src/gromacs/mdlib/repl_ex.cpp | 10 +-- src/gromacs/mdlib/rf_util.cpp | 2 +- src/gromacs/mdlib/shake.cpp | 4 +- src/gromacs/mdlib/shellfc.cpp | 2 +- src/gromacs/mdlib/sighandler.cpp | 2 +- src/gromacs/mdlib/sim_util.cpp | 14 ++-- src/gromacs/mdrun/md.cpp | 4 +- src/gromacs/mdrun/minimize.cpp | 20 +++--- src/gromacs/mdrun/runner.cpp | 2 +- src/gromacs/mdrun/tpi.cpp | 20 +++--- src/gromacs/mdtypes/inputrec.cpp | 2 +- src/gromacs/pbcutil/mshift.cpp | 2 +- src/gromacs/pulling/pull_rotation.cpp | 2 +- src/gromacs/selection/evaluate.cpp | 4 +- src/gromacs/selection/mempool.cpp | 6 +- src/gromacs/selection/parsetree.cpp | 2 +- src/gromacs/selection/sm_compare.cpp | 14 ++-- src/gromacs/selection/sm_insolidangle.cpp | 10 +-- src/gromacs/selection/sm_keywords.cpp | 10 +-- src/gromacs/selection/sm_merge.cpp | 14 ++-- src/gromacs/selection/sm_permute.cpp | 8 +-- src/gromacs/selection/sm_position.cpp | 18 ++--- src/gromacs/selection/sm_same.cpp | 14 ++-- src/gromacs/statistics/statistics.cpp | 6 +- src/gromacs/swap/swapcoords.cpp | 2 +- src/gromacs/tables/forcetable.cpp | 4 +- src/gromacs/timing/wallcycle.cpp | 8 +-- src/gromacs/tools/convert_tpr.cpp | 4 +- src/gromacs/topology/atomprop.cpp | 18 ++--- src/gromacs/topology/index.cpp | 6 +- src/gromacs/topology/mtop_util.cpp | 24 +++---- src/gromacs/topology/symtab.cpp | 2 +- src/gromacs/topology/topology.cpp | 2 +- .../modules/surfacearea.cpp | 20 +++--- src/gromacs/utility/binaryinformation.cpp | 2 +- src/gromacs/utility/cstringutil.cpp | 6 +- src/gromacs/utility/qsort_threadsafe.cpp | 24 +++---- src/gromacs/utility/smalloc.cpp | 14 ++-- 125 files changed, 549 insertions(+), 550 deletions(-) diff --git a/src/gromacs/analysisdata/modules/displacement.cpp b/src/gromacs/analysisdata/modules/displacement.cpp index ae8a05ed21..310572c3df 100644 --- a/src/gromacs/analysisdata/modules/displacement.cpp +++ b/src/gromacs/analysisdata/modules/displacement.cpp @@ -212,7 +212,7 @@ AnalysisDataDisplacementModule::frameStarted(const AnalysisDataFrameHeader &head // Allocate memory for all the positions once it is possible. if (_impl->max_store == -1 && !_impl->bFirst) { - _impl->max_store = _impl->nmax * (int)(_impl->tmax/_impl->dt + 1); + _impl->max_store = _impl->nmax * static_cast(_impl->tmax/_impl->dt + 1); srenew(_impl->oldval, _impl->max_store); } diff --git a/src/gromacs/commandline/filenm.cpp b/src/gromacs/commandline/filenm.cpp index e3461b3524..274661287d 100644 --- a/src/gromacs/commandline/filenm.cpp +++ b/src/gromacs/commandline/filenm.cpp @@ -158,7 +158,7 @@ gmx_bool ftp2bSet(int ftp, int nfile, const t_filenm fnm[]) { if (ftp == fnm[i].ftp) { - return (gmx_bool) IS_SET(fnm[i]); + return static_cast(IS_SET(fnm[i])); } } @@ -173,7 +173,7 @@ gmx_bool opt2bSet(const char *opt, int nfile, const t_filenm fnm[]) if (fileOption) { - return (gmx_bool) IS_SET(*fileOption); + return static_cast(IS_SET(*fileOption)); } GMX_RELEASE_ASSERT(false, "opt2bSet should be called with a valid option"); diff --git a/src/gromacs/commandline/pargs.cpp b/src/gromacs/commandline/pargs.cpp index 20975cb5fb..87a602ca65 100644 --- a/src/gromacs/commandline/pargs.cpp +++ b/src/gromacs/commandline/pargs.cpp @@ -566,8 +566,8 @@ gmx_bool parse_common_args(int *argc, char *argv[], unsigned long Flags, /* set program name, command line, and default values for output options */ output_env_init(oenv, gmx::getProgramContext(), - (time_unit_t)(timeUnit + 1), bView, // NOLINT(misc-misplaced-widening-cast) - (xvg_format_t)(xvgFormat + 1), 0); + static_cast(timeUnit + 1), bView, // NOLINT(misc-misplaced-widening-cast) + static_cast(xvgFormat + 1), 0); /* Extract Time info from arguments */ if (bBeginTimeSet) diff --git a/src/gromacs/correlationfunctions/autocorr.cpp b/src/gromacs/correlationfunctions/autocorr.cpp index 61dc522a28..63560a924a 100644 --- a/src/gromacs/correlationfunctions/autocorr.cpp +++ b/src/gromacs/correlationfunctions/autocorr.cpp @@ -525,7 +525,7 @@ static void do_four_core(unsigned long mode, int nframes, sfree(cfour); for (j = 0; (j < nframes); j++) { - c1[j] = csum[j]/(real)(nframes-j); + c1[j] = csum[j]/static_cast(nframes-j); } } diff --git a/src/gromacs/correlationfunctions/expfit.cpp b/src/gromacs/correlationfunctions/expfit.cpp index 61070fbee6..b8c3176c17 100644 --- a/src/gromacs/correlationfunctions/expfit.cpp +++ b/src/gromacs/correlationfunctions/expfit.cpp @@ -626,7 +626,7 @@ real do_lmfit(int ndata, const real c1[], real sig[], real dt, const real *x0, } else { - dy[j] = std::max(1.0e-7, (double)sig[i]); + dy[j] = std::max(1.0e-7, static_cast(sig[i])); } if (debug) { @@ -756,7 +756,7 @@ real fit_acf(int ncorr, int fitfn, const gmx_output_env_t *oenv, gmx_bool bVerbo { tendfit = ncorr*dt; } - nf_int = std::min(ncorr, (int)(tendfit/dt)); + nf_int = std::min(ncorr, static_cast(tendfit/dt)); sum = print_and_integrate(debug, nf_int, dt, c1, nullptr, 1); if (bPrint) @@ -841,7 +841,7 @@ real fit_acf(int ncorr, int fitfn, const gmx_output_env_t *oenv, gmx_bool bVerbo sig[i] = sqrt(ct_estimate+dt*i); } - nf_int = std::min(ncorr, (int)((tStart+1e-4)/dt)); + nf_int = std::min(ncorr, static_cast((tStart+1e-4)/dt)); sum = print_and_integrate(debug, nf_int, dt, c1, nullptr, 1); tail_corr = do_lmfit(ncorr, c1, sig, dt, nullptr, tStart, tendfit, oenv, bDebugMode(), fitfn, fitparm, 0, nullptr); diff --git a/src/gromacs/domdec/cellsizes.cpp b/src/gromacs/domdec/cellsizes.cpp index e85f2e726f..1a776ebf38 100644 --- a/src/gromacs/domdec/cellsizes.cpp +++ b/src/gromacs/domdec/cellsizes.cpp @@ -101,7 +101,7 @@ static void set_pme_maxshift(gmx_domdec_t *dd, gmx_ddpme_t *ddpme, for (s = 0; s < ns; s++) { /* PME slab s spreads atoms between box frac. s/ns and (s+1)/ns */ - pme_boundary = (real)s/ns; + pme_boundary = static_cast(s)/ns; while (sh + 1 < ns && ((s - (sh + 1) >= 0 && cellFrac[xmax[s - (sh + 1) ] + 1] + range > pme_boundary) || @@ -110,7 +110,7 @@ static void set_pme_maxshift(gmx_domdec_t *dd, gmx_ddpme_t *ddpme, { sh++; } - pme_boundary = (real)(s+1)/ns; + pme_boundary = static_cast(s+1)/ns; while (sh + 1 < ns && ((s + (sh + 1) < ns && cellFrac[xmin[s + (sh + 1) ] ] - range < pme_boundary) || @@ -759,10 +759,10 @@ static void distribute_dd_cell_sizes_dlb(gmx_domdec_t *dd, relative_to_absolute_cell_bounds(dd, ddbox, d1); } /* Convert the communicated shift from float to int */ - comm.ddpme[0].maxshift = (int)(cellFracRow[pos++] + 0.5); + comm.ddpme[0].maxshift = static_cast(cellFracRow[pos++] + 0.5); if (d >= 1) { - comm.ddpme[1].maxshift = (int)(cellFracRow[pos++] + 0.5); + comm.ddpme[1].maxshift = static_cast(cellFracRow[pos++] + 0.5); } } diff --git a/src/gromacs/domdec/domdec.cpp b/src/gromacs/domdec/domdec.cpp index b89a53f46d..2866d86fcb 100644 --- a/src/gromacs/domdec/domdec.cpp +++ b/src/gromacs/domdec/domdec.cpp @@ -1841,7 +1841,7 @@ static float dd_force_load(gmx_domdec_comm_t *comm) * is spurious CPU activity or MPI time, so we don't expect * that changes in the GPU wait time matter a lot here. */ - gpu_wait *= (comm->cycl_n[ddCyclF] - 1)/(float)comm->cycl_n[ddCyclF]; + gpu_wait *= (comm->cycl_n[ddCyclF] - 1)/static_cast(comm->cycl_n[ddCyclF]); } /* Sum the wait times over the ranks that share the same GPU */ MPI_Allreduce(&gpu_wait, &gpu_wait_sum, 1, MPI_FLOAT, MPI_SUM, @@ -1872,7 +1872,7 @@ static void set_slb_pme_dim_f(gmx_domdec_t *dd, int dim, real **dim_f) } else { - (*dim_f)[i] = (real)i/(real)dd->nc[dim]; + (*dim_f)[i] = static_cast(i)/static_cast(dd->nc[dim]); } } (*dim_f)[dd->nc[dim]] = 1; @@ -2223,7 +2223,7 @@ static void get_load_distribution(gmx_domdec_t *dd, gmx_wallcycle_t wcycle) pos++; if (d < dd->ndim-1) { - load->flags = (int)(load->load[pos++] + 0.5); + load->flags = static_cast(load->load[pos++] + 0.5); } if (d > 0) { @@ -2532,7 +2532,7 @@ static void dd_print_load_verbose(gmx_domdec_t *dd) } if (dd->nnodes > 1) { - fprintf(stderr, "imb F %2d%% ", (int)(dd_f_imbal(dd)*100+0.5)); + fprintf(stderr, "imb F %2d%% ", static_cast(dd_f_imbal(dd)*100+0.5)); } if (dd->comm->cycl_n[ddCyclPME]) { @@ -4185,7 +4185,7 @@ static void set_cell_limits_dlb(gmx_domdec_t *dd, * Later cellsize_limit is redetermined, * so we can not miss interactions due to this rounding. */ - npulse = (int)(0.96 + comm->cutoff/comm->cellsize_limit); + npulse = static_cast(0.96 + comm->cutoff/comm->cellsize_limit); } else { @@ -4200,8 +4200,8 @@ static void set_cell_limits_dlb(gmx_domdec_t *dd, for (d = 0; d < dd->ndim; d++) { dim = dd->dim[d]; - npulse_d = (int)(1 + dd->nc[dim]*comm->cutoff - /(ddbox->box_size[dim]*ddbox->skew_fac[dim]*dlb_scale)); + npulse_d = static_cast(1 + dd->nc[dim]*comm->cutoff + /(ddbox->box_size[dim]*ddbox->skew_fac[dim]*dlb_scale)); npulse_d_max = std::max(npulse_d_max, npulse_d); } npulse = std::min(npulse, npulse_d_max); @@ -4319,12 +4319,12 @@ static void set_ddgrid_parameters(FILE *fplog, gmx_domdec_t *dd, real dlb_scale, if (ir->ePBC == epbcNONE) { - vol_frac = 1 - 1/(double)dd->nnodes; + vol_frac = 1 - 1/static_cast(dd->nnodes); } else { vol_frac = - (1 + comm_box_frac(dd->nc, comm->cutoff, ddbox))/(double)dd->nnodes; + (1 + comm_box_frac(dd->nc, comm->cutoff, ddbox))/static_cast(dd->nnodes); } if (debug) { @@ -4465,7 +4465,7 @@ static gmx_bool test_dd_cutoff(t_commrec *cr, inv_cell_size *= DD_PRES_SCALE_MARGIN; } - np = 1 + (int)(cutoff_req*inv_cell_size*ddbox.skew_fac[dim]); + np = 1 + static_cast(cutoff_req*inv_cell_size*ddbox.skew_fac[dim]); if (!isDlbDisabled(dd->comm) && (dim < ddbox.npbcdim) && (dd->comm->cd[d].np_dlb > 0)) { diff --git a/src/gromacs/domdec/domdec_box.cpp b/src/gromacs/domdec/domdec_box.cpp index 96240bdd31..ebd4de8d1b 100644 --- a/src/gromacs/domdec/domdec_box.cpp +++ b/src/gromacs/domdec/domdec_box.cpp @@ -103,7 +103,7 @@ static void calc_pos_av_stddev(int n, const rvec *x, s1[d] = receiveBuffer[d]; s2[d] = receiveBuffer[DIM + d]; } - n = (int)(receiveBuffer[6] + 0.5); + n = static_cast(receiveBuffer[6] + 0.5); } #else // GMX_MPI GMX_UNUSED_VALUE(mpiCommunicator); diff --git a/src/gromacs/domdec/domdec_setup.cpp b/src/gromacs/domdec/domdec_setup.cpp index 6be8f7971d..84f1b0534e 100644 --- a/src/gromacs/domdec/domdec_setup.cpp +++ b/src/gromacs/domdec/domdec_setup.cpp @@ -134,7 +134,7 @@ static int lcd(int n1, int n2) /*! \brief Returns TRUE when there are enough PME ranks for the ratio */ static gmx_bool fits_pme_ratio(int nrank_tot, int nrank_pme, float ratio) { - return ((double)nrank_pme/(double)nrank_tot > 0.95*ratio); + return (static_cast(nrank_pme)/static_cast(nrank_tot) > 0.95*ratio); } /*! \brief Returns TRUE when npme out of ntot ranks doing PME is expected to give reasonable performance */ @@ -238,7 +238,7 @@ static int guess_npme(FILE *fplog, const gmx_mtop_t *mtop, const t_inputrec *ir, { gmx_fatal(FARGS, "Could not find an appropriate number of separate PME ranks. i.e. >= %5f*#ranks (%d) and <= #ranks/2 (%d) and reasonable performance wise (grid_x=%d, grid_y=%d).\n" "Use the -npme option of mdrun or change the number of ranks or the PME grid dimensions, see the manual for details.", - ratio, (int)(0.95*ratio*nrank_tot + 0.5), nrank_tot/2, ir->nkx, ir->nky); + ratio, static_cast(0.95*ratio*nrank_tot + 0.5), nrank_tot/2, ir->nkx, ir->nky); } else { @@ -491,7 +491,7 @@ static float comm_cost_est(real limit, real cutoff, } else { - comm_vol_xf = 1.0 - lcd(nc[i], npme[i])/(double)npme[i]; + comm_vol_xf = 1.0 - lcd(nc[i], npme[i])/static_cast(npme[i]); } comm_pme += 3*natoms*comm_vol_xf; } @@ -646,7 +646,7 @@ static real optimize_ncells(FILE *fplog, * Here we ignore SIMD bondeds as they always do (fast) PBC. */ count_bonded_distances(mtop, ir, &pbcdxr, nullptr); - pbcdxr /= (double)mtop->natoms; + pbcdxr /= static_cast(mtop->natoms); } else { @@ -689,7 +689,7 @@ static real optimize_ncells(FILE *fplog, fprintf(fplog, "The maximum allowed number of cells is:"); for (d = 0; d < DIM; d++) { - nmax = (int)(ddbox->box_size[d]*ddbox->skew_fac[d]/limit); + nmax = static_cast(ddbox->box_size[d]*ddbox->skew_fac[d]/limit); if (d >= ddbox->npbcdim && nmax < 2) { nmax = 2; diff --git a/src/gromacs/essentialdynamics/edsam.cpp b/src/gromacs/essentialdynamics/edsam.cpp index e535c5f5cc..e5b3e322f8 100644 --- a/src/gromacs/essentialdynamics/edsam.cpp +++ b/src/gromacs/essentialdynamics/edsam.cpp @@ -1421,7 +1421,7 @@ static real read_checked_edreal(FILE *file, const char *label) check(line, label); fgets2 (line, STRLEN, file); sscanf (line, max_ev_fmt_lf, &rdum); - return (real) rdum; /* always read as double and convert to single */ + return static_cast(rdum); /* always read as double and convert to single */ } @@ -1873,7 +1873,7 @@ static real rmsd_from_structure(rvec *x, /* The positions under consi rmsd += distance2(s->x[i], x[i]); } - rmsd /= (real) s->nr; + rmsd /= static_cast(s->nr); rmsd = sqrt(rmsd); return rmsd; diff --git a/src/gromacs/ewald/pme-load-balancing.cpp b/src/gromacs/ewald/pme-load-balancing.cpp index 6aa4e512b7..971a47e3e5 100644 --- a/src/gromacs/ewald/pme-load-balancing.cpp +++ b/src/gromacs/ewald/pme-load-balancing.cpp @@ -1084,7 +1084,7 @@ static void print_pme_loadbal_settings(pme_load_balancing_t *pme_lb, pp_ratio_temporary = pme_lb->setup[pme_lb->cur].rlistInner / pme_lb->setup[0].rlistInner; pp_ratio = gmx::power3(pp_ratio_temporary); grid_ratio = pme_grid_points(&pme_lb->setup[pme_lb->cur])/ - (double)pme_grid_points(&pme_lb->setup[0]); + static_cast(pme_grid_points(&pme_lb->setup[0])); fprintf(fplog, "\n"); fprintf(fplog, " P P - P M E L O A D B A L A N C I N G\n"); diff --git a/src/gromacs/ewald/pme-redistribute.cpp b/src/gromacs/ewald/pme-redistribute.cpp index 045646a4ad..e0b8defda5 100644 --- a/src/gromacs/ewald/pme-redistribute.cpp +++ b/src/gromacs/ewald/pme-redistribute.cpp @@ -87,7 +87,7 @@ static void pme_calc_pidx(int start, int end, xptr = x[i]; /* Fractional coordinates along box vectors */ s = nslab*(xptr[XX]*rxx + xptr[YY]*ryx + xptr[ZZ]*rzx); - si = (int)(s + 2*nslab) % nslab; + si = static_cast(s + 2*nslab) % nslab; pd[i] = si; count[si]++; } @@ -102,7 +102,7 @@ static void pme_calc_pidx(int start, int end, xptr = x[i]; /* Fractional coordinates along box vectors */ s = nslab*(xptr[YY]*ryy + xptr[ZZ]*rzy); - si = (int)(s + 2*nslab) % nslab; + si = static_cast(s + 2*nslab) % nslab; pd[i] = si; count[si]++; } diff --git a/src/gromacs/ewald/pme.cpp b/src/gromacs/ewald/pme.cpp index ccb6e7af35..3d3f9220d4 100644 --- a/src/gromacs/ewald/pme.cpp +++ b/src/gromacs/ewald/pme.cpp @@ -301,7 +301,7 @@ static double estimate_pme_load_imbalance(struct gmx_pme_t *pme) /* pme_solve is roughly double the cost of an fft */ - return (n1 + n2 + 3*n3)/(double)(6*pme->nkx*pme->nky*pme->nkz); + return (n1 + n2 + 3*n3)/static_cast(6*pme->nkx*pme->nky*pme->nkz); } /*! \brief Initialize atom communication data structure */ @@ -809,7 +809,7 @@ gmx_pme_t *gmx_pme_init(const t_commrec *cr, " PME grid_x (%d) and grid_y (%d) should be divisible by #PME_ranks_x (%d)\n" " and PME grid_y (%d) and grid_z (%d) should be divisible by #PME_ranks_y (%d)\n" "\n", - (int)((imbal-1)*100 + 0.5), + static_cast((imbal-1)*100 + 0.5), pme->nkx, pme->nky, pme->nnodes_major, pme->nky, pme->nkz, pme->nnodes_minor); } diff --git a/src/gromacs/fft/fft5d.cpp b/src/gromacs/fft/fft5d.cpp index a355672c13..12c1e010f8 100644 --- a/src/gromacs/fft/fft5d.cpp +++ b/src/gromacs/fft/fft5d.cpp @@ -241,12 +241,12 @@ fft5d_plan fft5d_plan_3d(int NG, int MG, int KG, MPI_Comm comm[2], int flags, t_ /*for transpose we need to know the size for each processor not only our own size*/ - N0 = (int*)malloc(P[0]*sizeof(int)); N1 = (int*)malloc(P[1]*sizeof(int)); - M0 = (int*)malloc(P[0]*sizeof(int)); M1 = (int*)malloc(P[1]*sizeof(int)); - K0 = (int*)malloc(P[0]*sizeof(int)); K1 = (int*)malloc(P[1]*sizeof(int)); - oN0 = (int*)malloc(P[0]*sizeof(int)); oN1 = (int*)malloc(P[1]*sizeof(int)); - oM0 = (int*)malloc(P[0]*sizeof(int)); oM1 = (int*)malloc(P[1]*sizeof(int)); - oK0 = (int*)malloc(P[0]*sizeof(int)); oK1 = (int*)malloc(P[1]*sizeof(int)); + N0 = static_cast(malloc(P[0]*sizeof(int))); N1 = static_cast(malloc(P[1]*sizeof(int))); + M0 = static_cast(malloc(P[0]*sizeof(int))); M1 = static_cast(malloc(P[1]*sizeof(int))); + K0 = static_cast(malloc(P[0]*sizeof(int))); K1 = static_cast(malloc(P[1]*sizeof(int))); + oN0 = static_cast(malloc(P[0]*sizeof(int))); oN1 = static_cast(malloc(P[1]*sizeof(int))); + oM0 = static_cast(malloc(P[0]*sizeof(int))); oM1 = static_cast(malloc(P[1]*sizeof(int))); + oK0 = static_cast(malloc(P[0]*sizeof(int))); oK1 = static_cast(malloc(P[1]*sizeof(int))); for (i = 0; i < P[0]; i++) { @@ -430,7 +430,7 @@ fft5d_plan fft5d_plan_3d(int NG, int MG, int KG, MPI_Comm comm[2], int flags, t_ } } - plan = (fft5d_plan)calloc(1, sizeof(struct fft5d_plan_t)); + plan = static_cast(calloc(1, sizeof(struct fft5d_plan_t))); if (debug) @@ -542,21 +542,21 @@ fft5d_plan fft5d_plan_3d(int NG, int MG, int KG, MPI_Comm comm[2], int flags, t_ { plan->p3d = FFTW(plan_guru_dft_r2c)(/*rank*/ 3, dims, /*howmany*/ 0, /*howmany_dims*/ nullptr, - (real*)lin, (FFTW(complex) *) lout, + reinterpret_cast(lin), reinterpret_cast(lout), /*flags*/ fftwflags); } else if ((flags&FFT5D_REALCOMPLEX) && (flags&FFT5D_BACKWARD)) { plan->p3d = FFTW(plan_guru_dft_c2r)(/*rank*/ 3, dims, /*howmany*/ 0, /*howmany_dims*/ nullptr, - (FFTW(complex) *) lin, (real*)lout, + reinterpret_cast(lin), reinterpret_cast(lout), /*flags*/ fftwflags); } else { plan->p3d = FFTW(plan_guru_dft)(/*rank*/ 3, dims, /*howmany*/ 0, /*howmany_dims*/ nullptr, - (FFTW(complex) *) lin, (FFTW(complex) *) lout, + reinterpret_cast(lin), reinterpret_cast(lout), /*sign*/ (flags&FFT5D_BACKWARD) ? 1 : -1, /*flags*/ fftwflags); } #ifdef FFT5D_THREADS @@ -576,7 +576,7 @@ fft5d_plan fft5d_plan_3d(int NG, int MG, int KG, MPI_Comm comm[2], int flags, t_ fprintf(debug, "FFT5D: Plan s %d rC %d M %d pK %d C %d lsize %d\n", s, rC[s], M[s], pK[s], C[s], lsize); } - plan->p1d[s] = (gmx_fft_t*)malloc(sizeof(gmx_fft_t)*nthreads); + plan->p1d[s] = static_cast(malloc(sizeof(gmx_fft_t)*nthreads)); /* Make sure that the init routines are only called by one thread at a time and in order (later is only important to not confuse valgrind) @@ -1113,11 +1113,11 @@ void fft5d_execute(fft5d_plan plan, int thread, fft5d_time times) #if GMX_MPI if ((s == 0 && !(plan->flags&FFT5D_ORDER_YZ)) || (s == 1 && (plan->flags&FFT5D_ORDER_YZ))) { - MPI_Alltoall((real *)lout2, N[s]*pM[s]*K[s]*sizeof(t_complex)/sizeof(real), GMX_MPI_REAL, (real *)lout3, N[s]*pM[s]*K[s]*sizeof(t_complex)/sizeof(real), GMX_MPI_REAL, cart[s]); + MPI_Alltoall(reinterpret_cast(lout2), N[s]*pM[s]*K[s]*sizeof(t_complex)/sizeof(real), GMX_MPI_REAL, reinterpret_cast(lout3), N[s]*pM[s]*K[s]*sizeof(t_complex)/sizeof(real), GMX_MPI_REAL, cart[s]); } else { - MPI_Alltoall((real *)lout2, N[s]*M[s]*pK[s]*sizeof(t_complex)/sizeof(real), GMX_MPI_REAL, (real *)lout3, N[s]*M[s]*pK[s]*sizeof(t_complex)/sizeof(real), GMX_MPI_REAL, cart[s]); + MPI_Alltoall(reinterpret_cast(lout2), N[s]*M[s]*pK[s]*sizeof(t_complex)/sizeof(real), GMX_MPI_REAL, reinterpret_cast(lout3), N[s]*M[s]*pK[s]*sizeof(t_complex)/sizeof(real), GMX_MPI_REAL, cart[s]); } #else gmx_incons("fft5d MPI call without MPI configuration"); diff --git a/src/gromacs/fft/fft_fftw3.cpp b/src/gromacs/fft/fft_fftw3.cpp index b8eceda133..75a0f80e94 100644 --- a/src/gromacs/fft/fft_fftw3.cpp +++ b/src/gromacs/fft/fft_fftw3.cpp @@ -2,7 +2,7 @@ * This file is part of the GROMACS molecular simulation package. * * Copyright (c) 1991-2003 David van der Spoel, Erik Lindahl, University of Groningen. - * Copyright (c) 2013,2014,2015,2017, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -128,14 +128,14 @@ gmx_fft_init_many_1d(gmx_fft_t * pfft, *pfft = nullptr; FFTW_LOCK; - if ( (fft = (gmx_fft_t)FFTWPREFIX(malloc)(sizeof(struct gmx_fft))) == nullptr) + if ( (fft = static_cast(FFTWPREFIX(malloc)(sizeof(struct gmx_fft)))) == nullptr) { FFTW_UNLOCK; return ENOMEM; } /* allocate aligned, and extra memory to make it unaligned */ - p1 = (FFTWPREFIX(complex) *) FFTWPREFIX(malloc)(sizeof(FFTWPREFIX(complex))*(nx+2)*howmany); + p1 = static_cast(FFTWPREFIX(malloc)(sizeof(FFTWPREFIX(complex))*(nx+2)*howmany)); if (p1 == nullptr) { FFTWPREFIX(free)(fft); @@ -143,7 +143,7 @@ gmx_fft_init_many_1d(gmx_fft_t * pfft, return ENOMEM; } - p2 = (FFTWPREFIX(complex) *) FFTWPREFIX(malloc)(sizeof(FFTWPREFIX(complex))*(nx+2)*howmany); + p2 = static_cast(FFTWPREFIX(malloc)(sizeof(FFTWPREFIX(complex))*(nx+2)*howmany)); if (p2 == nullptr) { FFTWPREFIX(free)(p1); @@ -245,14 +245,14 @@ gmx_fft_init_many_1d_real(gmx_fft_t * pfft, *pfft = nullptr; FFTW_LOCK; - if ( (fft = (gmx_fft_t) FFTWPREFIX(malloc)(sizeof(struct gmx_fft))) == nullptr) + if ( (fft = static_cast(FFTWPREFIX(malloc)(sizeof(struct gmx_fft)))) == nullptr) { FFTW_UNLOCK; return ENOMEM; } /* allocate aligned, and extra memory to make it unaligned */ - p1 = (real *) FFTWPREFIX(malloc)(sizeof(real)*(nx/2+1)*2*howmany + 8); + p1 = static_cast(FFTWPREFIX(malloc)(sizeof(real)*(nx/2+1)*2*howmany + 8)); if (p1 == nullptr) { FFTWPREFIX(free)(fft); @@ -260,7 +260,7 @@ gmx_fft_init_many_1d_real(gmx_fft_t * pfft, return ENOMEM; } - p2 = (real *) FFTWPREFIX(malloc)(sizeof(real)*(nx/2+1)*2*howmany + 8); + p2 = static_cast(FFTWPREFIX(malloc)(sizeof(real)*(nx/2+1)*2*howmany + 8)); if (p2 == nullptr) { FFTWPREFIX(free)(p1); @@ -287,15 +287,15 @@ gmx_fft_init_many_1d_real(gmx_fft_t * pfft, fftw_complex *out, const int *onembed, int ostride, int odist, unsigned flag */ - fft->plan[0][0][1] = FFTWPREFIX(plan_many_dft_r2c)(1, &nx, howmany, up1, nullptr, 1, (nx/2+1) *2, (FFTWPREFIX(complex) *) up2, nullptr, 1, (nx/2+1), fftw_flags); - fft->plan[0][1][1] = FFTWPREFIX(plan_many_dft_r2c)(1, &nx, howmany, up1, nullptr, 1, (nx/2+1) *2, (FFTWPREFIX(complex) *) up1, nullptr, 1, (nx/2+1), fftw_flags); - fft->plan[1][0][1] = FFTWPREFIX(plan_many_dft_r2c)(1, &nx, howmany, p1, nullptr, 1, (nx/2+1) *2, (FFTWPREFIX(complex) *) p2, nullptr, 1, (nx/2+1), fftw_flags); - fft->plan[1][1][1] = FFTWPREFIX(plan_many_dft_r2c)(1, &nx, howmany, p1, nullptr, 1, (nx/2+1) *2, (FFTWPREFIX(complex) *) p1, nullptr, 1, (nx/2+1), fftw_flags); + fft->plan[0][0][1] = FFTWPREFIX(plan_many_dft_r2c)(1, &nx, howmany, up1, nullptr, 1, (nx/2+1) *2, reinterpret_cast(up2), nullptr, 1, (nx/2+1), fftw_flags); + fft->plan[0][1][1] = FFTWPREFIX(plan_many_dft_r2c)(1, &nx, howmany, up1, nullptr, 1, (nx/2+1) *2, reinterpret_cast(up1), nullptr, 1, (nx/2+1), fftw_flags); + fft->plan[1][0][1] = FFTWPREFIX(plan_many_dft_r2c)(1, &nx, howmany, p1, nullptr, 1, (nx/2+1) *2, reinterpret_cast(p2), nullptr, 1, (nx/2+1), fftw_flags); + fft->plan[1][1][1] = FFTWPREFIX(plan_many_dft_r2c)(1, &nx, howmany, p1, nullptr, 1, (nx/2+1) *2, reinterpret_cast(p1), nullptr, 1, (nx/2+1), fftw_flags); - fft->plan[0][0][0] = FFTWPREFIX(plan_many_dft_c2r)(1, &nx, howmany, (FFTWPREFIX(complex) *) up1, nullptr, 1, (nx/2+1), up2, nullptr, 1, (nx/2+1) *2, fftw_flags); - fft->plan[0][1][0] = FFTWPREFIX(plan_many_dft_c2r)(1, &nx, howmany, (FFTWPREFIX(complex) *) up1, nullptr, 1, (nx/2+1), up1, nullptr, 1, (nx/2+1) *2, fftw_flags); - fft->plan[1][0][0] = FFTWPREFIX(plan_many_dft_c2r)(1, &nx, howmany, (FFTWPREFIX(complex) *) p1, nullptr, 1, (nx/2+1), p2, nullptr, 1, (nx/2+1) *2, fftw_flags); - fft->plan[1][1][0] = FFTWPREFIX(plan_many_dft_c2r)(1, &nx, howmany, (FFTWPREFIX(complex) *) p1, nullptr, 1, (nx/2+1), p1, nullptr, 1, (nx/2+1) *2, fftw_flags); + fft->plan[0][0][0] = FFTWPREFIX(plan_many_dft_c2r)(1, &nx, howmany, reinterpret_cast(up1), nullptr, 1, (nx/2+1), up2, nullptr, 1, (nx/2+1) *2, fftw_flags); + fft->plan[0][1][0] = FFTWPREFIX(plan_many_dft_c2r)(1, &nx, howmany, reinterpret_cast(up1), nullptr, 1, (nx/2+1), up1, nullptr, 1, (nx/2+1) *2, fftw_flags); + fft->plan[1][0][0] = FFTWPREFIX(plan_many_dft_c2r)(1, &nx, howmany, reinterpret_cast(p1), nullptr, 1, (nx/2+1), p2, nullptr, 1, (nx/2+1) *2, fftw_flags); + fft->plan[1][1][0] = FFTWPREFIX(plan_many_dft_c2r)(1, &nx, howmany, reinterpret_cast(p1), nullptr, 1, (nx/2+1), p1, nullptr, 1, (nx/2+1) *2, fftw_flags); for (i = 0; i < 2; i++) { @@ -356,14 +356,14 @@ gmx_fft_init_2d_real(gmx_fft_t * pfft, *pfft = nullptr; FFTW_LOCK; - if ( (fft = (gmx_fft_t) FFTWPREFIX(malloc)(sizeof(struct gmx_fft))) == nullptr) + if ( (fft = static_cast(FFTWPREFIX(malloc)(sizeof(struct gmx_fft)))) == nullptr) { FFTW_UNLOCK; return ENOMEM; } /* allocate aligned, and extra memory to make it unaligned */ - p1 = (real *) FFTWPREFIX(malloc)(sizeof(real) *( nx*(ny/2+1)*2 + 2) ); + p1 = static_cast(FFTWPREFIX(malloc)(sizeof(real) *( nx*(ny/2+1)*2 + 2) )); if (p1 == nullptr) { FFTWPREFIX(free)(fft); @@ -371,7 +371,7 @@ gmx_fft_init_2d_real(gmx_fft_t * pfft, return ENOMEM; } - p2 = (real *) FFTWPREFIX(malloc)(sizeof(real) *( nx*(ny/2+1)*2 + 2) ); + p2 = static_cast(FFTWPREFIX(malloc)(sizeof(real) *( nx*(ny/2+1)*2 + 2) )); if (p2 == nullptr) { FFTWPREFIX(free)(p1); @@ -393,15 +393,15 @@ gmx_fft_init_2d_real(gmx_fft_t * pfft, up2 = (real *)pc; - fft->plan[0][0][0] = FFTWPREFIX(plan_dft_c2r_2d)(nx, ny, (FFTWPREFIX(complex) *) up1, up2, fftw_flags); - fft->plan[0][0][1] = FFTWPREFIX(plan_dft_r2c_2d)(nx, ny, up1, (FFTWPREFIX(complex) *) up2, fftw_flags); - fft->plan[0][1][0] = FFTWPREFIX(plan_dft_c2r_2d)(nx, ny, (FFTWPREFIX(complex) *) up1, up1, fftw_flags); - fft->plan[0][1][1] = FFTWPREFIX(plan_dft_r2c_2d)(nx, ny, up1, (FFTWPREFIX(complex) *) up1, fftw_flags); + fft->plan[0][0][0] = FFTWPREFIX(plan_dft_c2r_2d)(nx, ny, reinterpret_cast(up1), up2, fftw_flags); + fft->plan[0][0][1] = FFTWPREFIX(plan_dft_r2c_2d)(nx, ny, up1, reinterpret_cast(up2), fftw_flags); + fft->plan[0][1][0] = FFTWPREFIX(plan_dft_c2r_2d)(nx, ny, reinterpret_cast(up1), up1, fftw_flags); + fft->plan[0][1][1] = FFTWPREFIX(plan_dft_r2c_2d)(nx, ny, up1, reinterpret_cast(up1), fftw_flags); - fft->plan[1][0][0] = FFTWPREFIX(plan_dft_c2r_2d)(nx, ny, (FFTWPREFIX(complex) *) p1, p2, fftw_flags); - fft->plan[1][0][1] = FFTWPREFIX(plan_dft_r2c_2d)(nx, ny, p1, (FFTWPREFIX(complex) *) p2, fftw_flags); - fft->plan[1][1][0] = FFTWPREFIX(plan_dft_c2r_2d)(nx, ny, (FFTWPREFIX(complex) *) p1, p1, fftw_flags); - fft->plan[1][1][1] = FFTWPREFIX(plan_dft_r2c_2d)(nx, ny, p1, (FFTWPREFIX(complex) *) p1, fftw_flags); + fft->plan[1][0][0] = FFTWPREFIX(plan_dft_c2r_2d)(nx, ny, reinterpret_cast(p1), p2, fftw_flags); + fft->plan[1][0][1] = FFTWPREFIX(plan_dft_r2c_2d)(nx, ny, p1, reinterpret_cast(p2), fftw_flags); + fft->plan[1][1][0] = FFTWPREFIX(plan_dft_c2r_2d)(nx, ny, reinterpret_cast(p1), p1, fftw_flags); + fft->plan[1][1][1] = FFTWPREFIX(plan_dft_r2c_2d)(nx, ny, p1, reinterpret_cast(p1), fftw_flags); for (i = 0; i < 2; i++) @@ -455,8 +455,8 @@ gmx_fft_1d (gmx_fft_t fft, } FFTWPREFIX(execute_dft)(fft->plan[aligned][inplace][isforward], - (FFTWPREFIX(complex) *) in_data, - (FFTWPREFIX(complex) *) out_data); + static_cast(in_data), + static_cast(out_data)); return 0; } @@ -491,12 +491,12 @@ gmx_fft_1d_real (gmx_fft_t fft, if (isforward) { FFTWPREFIX(execute_dft_r2c)(fft->plan[aligned][inplace][isforward], - (real *)in_data, (FFTWPREFIX(complex) *) out_data); + static_cast(in_data), static_cast(out_data)); } else { FFTWPREFIX(execute_dft_c2r)(fft->plan[aligned][inplace][isforward], - (FFTWPREFIX(complex) *) in_data, (real *)out_data); + static_cast(in_data), static_cast(out_data)); } return 0; @@ -532,14 +532,14 @@ gmx_fft_2d_real (gmx_fft_t fft, if (isforward) { FFTWPREFIX(execute_dft_r2c)(fft->plan[aligned][inplace][isforward], - (real *)in_data, - (FFTWPREFIX(complex) *) out_data); + static_cast(in_data), + static_cast(out_data)); } else { FFTWPREFIX(execute_dft_c2r)(fft->plan[aligned][inplace][isforward], - (FFTWPREFIX(complex) *) in_data, - (real *)out_data); + static_cast(in_data), + static_cast(out_data)); } diff --git a/src/gromacs/fft/parallel_3dfft.cpp b/src/gromacs/fft/parallel_3dfft.cpp index 64f97b6b99..f32feca9a5 100644 --- a/src/gromacs/fft/parallel_3dfft.cpp +++ b/src/gromacs/fft/parallel_3dfft.cpp @@ -83,10 +83,10 @@ gmx_parallel_3dfft_init (gmx_parallel_3dfft_t * pfft_setup, Nb = K; Mb = rN; Kb = M; /* currently always true because ORDER_YZ always set */ } - (*pfft_setup)->p1 = fft5d_plan_3d(rN, M, K, rcomm, flags, (t_complex**)real_data, complex_data, &buf1, &buf2, nthreads, realGridAllocation); + (*pfft_setup)->p1 = fft5d_plan_3d(rN, M, K, rcomm, flags, reinterpret_cast(real_data), complex_data, &buf1, &buf2, nthreads, realGridAllocation); (*pfft_setup)->p2 = fft5d_plan_3d(Nb, Mb, Kb, rcomm, - (flags|FFT5D_BACKWARD|FFT5D_NOMALLOC)^FFT5D_ORDER_YZ, complex_data, (t_complex**)real_data, &buf1, &buf2, nthreads); + (flags|FFT5D_BACKWARD|FFT5D_NOMALLOC)^FFT5D_ORDER_YZ, complex_data, reinterpret_cast(real_data), &buf1, &buf2, nthreads); return (*pfft_setup)->p1 != nullptr && (*pfft_setup)->p2 != nullptr; } diff --git a/src/gromacs/fileio/enxio.cpp b/src/gromacs/fileio/enxio.cpp index 57dbd83469..02858e0764 100644 --- a/src/gromacs/fileio/enxio.cpp +++ b/src/gromacs/fileio/enxio.cpp @@ -695,7 +695,7 @@ static gmx_bool do_eheader(ener_file_t ef, int *file_version, t_enxframe *fr, *bOK = *bOK && gmx_fio_do_int(ef->fio, typenr); *bOK = *bOK && gmx_fio_do_int(ef->fio, sub->nr); - sub->type = (xdr_datatype)typenr; + sub->type = static_cast(typenr); } } } @@ -821,7 +821,7 @@ ener_file_t open_enx(const char *fn, const char *mode) /* Now check whether this file is in single precision */ if (!bWrongPrecision && ((fr->e_size && (fr->nre == nre) && - (nre*4*(long int)sizeof(float) == fr->e_size)) ) ) + (nre*4*static_cast(sizeof(float)) == fr->e_size)) ) ) { fprintf(stderr, "Opened %s as single precision energy file\n", fn); free_enxnms(nre, nms); @@ -838,7 +838,7 @@ ener_file_t open_enx(const char *fn, const char *mode) } if (((fr->e_size && (fr->nre == nre) && - (nre*4*(long int)sizeof(double) == fr->e_size)) )) + (nre*4*static_cast(sizeof(double)) == fr->e_size)) )) { fprintf(stderr, "Opened %s as double precision energy file\n", fn); @@ -918,7 +918,7 @@ static void convert_full_sums(ener_old_t *ener_old, t_enxframe *fr) fr->ener[i].eav = eav_all - ener_old->ener_prev[i].eav - gmx::square(ener_old->ener_prev[i].esum/(nstep_all - fr->nsum) - esum_all/nstep_all)* - (nstep_all - fr->nsum)*nstep_all/(double)fr->nsum; + (nstep_all - fr->nsum)*nstep_all/static_cast(fr->nsum); ener_old->ener_prev[i].esum = esum_all; ener_old->ener_prev[i].eav = eav_all; } @@ -1431,7 +1431,7 @@ static void cmp_eblocks(t_enxframe *fr1, t_enxframe *fr2, real ftol, real abstol s1 = &(b1->sub[i]); s2 = &(b2->sub[i]); - cmp_int(stdout, buf, -1, (int)s1->type, (int)s2->type); + cmp_int(stdout, buf, -1, static_cast(s1->type), static_cast(s2->type)); cmp_int64(stdout, buf, s1->nr, s2->nr); if ((s1->type == s2->type) && (s1->nr == s2->nr)) diff --git a/src/gromacs/fileio/espio.cpp b/src/gromacs/fileio/espio.cpp index f254eb0459..6e146861b7 100644 --- a/src/gromacs/fileio/espio.cpp +++ b/src/gromacs/fileio/espio.cpp @@ -88,7 +88,7 @@ static int get_espresso_word(FILE *fp, char word[]) } else { - word[nc++] = (char)i; + word[nc++] = static_cast(i); } } } diff --git a/src/gromacs/fileio/gmxfio-xdr.cpp b/src/gromacs/fileio/gmxfio-xdr.cpp index cd8789d7ac..11a4add8ff 100644 --- a/src/gromacs/fileio/gmxfio-xdr.cpp +++ b/src/gromacs/fileio/gmxfio-xdr.cpp @@ -127,84 +127,84 @@ static gmx_bool do_xdr(t_fileio *fio, void *item, int nitem, int eio, { if (item && !fio->bRead) { - d = *((real *) item); + d = *(static_cast(item)); } res = xdr_double(fio->xdr, &d); if (item) { - *((real *) item) = d; + *(static_cast(item)) = d; } } else { if (item && !fio->bRead) { - f = *((real *) item); + f = *(static_cast(item)); } res = xdr_float(fio->xdr, &f); if (item) { - *((real *) item) = f; + *(static_cast(item)) = f; } } break; case eioFLOAT: if (item && !fio->bRead) { - f = *((float *) item); + f = *(static_cast(item)); } res = xdr_float(fio->xdr, &f); if (item) { - *((float *) item) = f; + *(static_cast(item)) = f; } break; case eioDOUBLE: if (item && !fio->bRead) { - d = *((double *) item); + d = *(static_cast(item)); } res = xdr_double(fio->xdr, &d); if (item) { - *((double *) item) = d; + *(static_cast(item)) = d; } break; case eioINT: if (item && !fio->bRead) { - idum = *(int *) item; + idum = *static_cast(item); } res = xdr_int(fio->xdr, &idum); if (item) { - *(int *) item = idum; + *static_cast(item) = idum; } break; case eioINT64: if (item && !fio->bRead) { - sdum = *(int64_t *) item; + sdum = *static_cast(item); } res = xdr_int64(fio->xdr, &sdum); if (item) { - *(int64_t *) item = sdum; + *static_cast(item) = sdum; } break; case eioUCHAR: if (item && !fio->bRead) { - ucdum = *(unsigned char *) item; + ucdum = *static_cast(item); } res = xdr_u_char(fio->xdr, &ucdum); if (item) { - *(unsigned char *) item = ucdum; + *static_cast(item) = ucdum; } break; case eioNUCHAR: - ucptr = (unsigned char *) item; + ucptr = static_cast(item); res = 1; for (j = 0; (j < nitem) && res; j++) { @@ -214,12 +214,12 @@ static gmx_bool do_xdr(t_fileio *fio, void *item, int nitem, int eio, case eioUSHORT: if (item && !fio->bRead) { - us = *(unsigned short *) item; + us = *static_cast(item); } - res = xdr_u_short(fio->xdr, (unsigned short *) &us); + res = xdr_u_short(fio->xdr, &us); if (item) { - *(unsigned short *) item = us; + *static_cast(item) = us; } break; case eioRVEC: @@ -229,17 +229,17 @@ static gmx_bool do_xdr(t_fileio *fio, void *item, int nitem, int eio, { for (m = 0; (m < DIM); m++) { - dvec[m] = ((real *) item)[m]; + dvec[m] = (static_cast(item))[m]; } } - res = xdr_vector(fio->xdr, (char *) dvec, DIM, + res = xdr_vector(fio->xdr, reinterpret_cast(dvec), DIM, static_cast(sizeof(double)), - (xdrproc_t) xdr_double); + reinterpret_cast(xdr_double)); if (item) { for (m = 0; (m < DIM); m++) { - ((real *) item)[m] = dvec[m]; + (static_cast(item))[m] = dvec[m]; } } } @@ -249,17 +249,17 @@ static gmx_bool do_xdr(t_fileio *fio, void *item, int nitem, int eio, { for (m = 0; (m < DIM); m++) { - fvec[m] = ((real *) item)[m]; + fvec[m] = (static_cast(item))[m]; } } - res = xdr_vector(fio->xdr, (char *) fvec, DIM, + res = xdr_vector(fio->xdr, reinterpret_cast(fvec), DIM, static_cast(sizeof(float)), - (xdrproc_t) xdr_float); + reinterpret_cast(xdr_float)); if (item) { for (m = 0; (m < DIM); m++) { - ((real *) item)[m] = fvec[m]; + (static_cast(item))[m] = fvec[m]; } } } @@ -271,13 +271,13 @@ static gmx_bool do_xdr(t_fileio *fio, void *item, int nitem, int eio, { if (item) { - ptr = ((rvec *) item)[j]; + ptr = (static_cast(item))[j]; } res = do_xdr(fio, ptr, 1, eioRVEC, desc, srcfile, line); } break; case eioIVEC: - iptr = (int *) item; + iptr = static_cast(item); res = 1; for (m = 0; (m < DIM) && res; m++) { @@ -301,7 +301,7 @@ static gmx_bool do_xdr(t_fileio *fio, void *item, int nitem, int eio, { if (!fio->bRead) { - slen = strlen((char *) item) + 1; + slen = strlen(static_cast(item)) + 1; } else { @@ -324,7 +324,7 @@ static gmx_bool do_xdr(t_fileio *fio, void *item, int nitem, int eio, } else { - cptr = (char *)item; + cptr = static_cast(item); } if (cptr) { diff --git a/src/gromacs/fileio/gmxfio.cpp b/src/gromacs/fileio/gmxfio.cpp index 71a0132495..993fe341dd 100644 --- a/src/gromacs/fileio/gmxfio.cpp +++ b/src/gromacs/fileio/gmxfio.cpp @@ -478,7 +478,7 @@ static int gmx_fio_int_get_file_md5(t_fileio *fio, gmx_off_t offset, snew(buf, CPT_CHK_LEN); /* the read puts the file position back to offset */ - if ((gmx_off_t)fread(buf, 1, read_len, fio->fp) != read_len) + if (static_cast(fread(buf, 1, read_len, fio->fp)) != read_len) { /* not fatal: md5sum check to prevent overwriting files * works (less safe) without @@ -517,7 +517,7 @@ static int gmx_fio_int_get_file_md5(t_fileio *fio, gmx_off_t offset, if (debug) { - fprintf(debug, "chksum %s readlen %ld\n", fio->fn, (long int)read_len); + fprintf(debug, "chksum %s readlen %ld\n", fio->fn, static_cast(read_len)); } if (!ret) diff --git a/src/gromacs/fileio/libxdrf.cpp b/src/gromacs/fileio/libxdrf.cpp index 1aa2ed2720..a5e35d94e2 100644 --- a/src/gromacs/fileio/libxdrf.cpp +++ b/src/gromacs/fileio/libxdrf.cpp @@ -449,7 +449,7 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision) if (*size <= 9) { return (xdr_vector(xdrs, reinterpret_cast(fp), static_cast(size3), - static_cast(sizeof(*fp)), (xdrproc_t)xdr_float)); + static_cast(sizeof(*fp)), reinterpret_cast(xdr_float))); } if (xdr_float(xdrs, precision) == 0) @@ -582,9 +582,9 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision) return 0; } - if ((float)maxint[0] - (float)minint[0] >= MAXABS || - (float)maxint[1] - (float)minint[1] >= MAXABS || - (float)maxint[2] - (float)minint[2] >= MAXABS) + if (static_cast(maxint[0]) - static_cast(minint[0]) >= MAXABS || + static_cast(maxint[1]) - static_cast(minint[1]) >= MAXABS || + static_cast(maxint[2]) - static_cast(minint[2]) >= MAXABS) { /* turning value in unsigned by subtracting minint * would cause overflow @@ -796,7 +796,7 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision) { *precision = -1; return (xdr_vector(xdrs, reinterpret_cast(fp), static_cast(size3), - static_cast(sizeof(*fp)), (xdrproc_t)xdr_float)); + static_cast(sizeof(*fp)), reinterpret_cast(xdr_float))); } if (xdr_float(xdrs, precision) == 0) { diff --git a/src/gromacs/fileio/matio.cpp b/src/gromacs/fileio/matio.cpp index c125394cf9..a9190bc359 100644 --- a/src/gromacs/fileio/matio.cpp +++ b/src/gromacs/fileio/matio.cpp @@ -667,7 +667,7 @@ static void write_xpm_map3(FILE *out, int n_x, int n_y, int *nlevels, if (*nlevels > NMAP*NMAP) { fprintf(stderr, "Warning, too many levels (%d) in matrix, using %d only\n", - *nlevels, (int)(NMAP*NMAP)); + *nlevels, static_cast(NMAP*NMAP)); *nlevels = NMAP*NMAP; } else if (*nlevels < 2) @@ -817,7 +817,7 @@ static void write_xpm_map(FILE *out, int n_x, int n_y, int *nlevels, if (*nlevels > NMAP*NMAP) { fprintf(stderr, "Warning, too many levels (%d) in matrix, using %d only\n", - *nlevels, (int)(NMAP*NMAP)); + *nlevels, static_cast(NMAP*NMAP)); *nlevels = NMAP*NMAP; } else if (*nlevels < 2) diff --git a/src/gromacs/fileio/md5.cpp b/src/gromacs/fileio/md5.cpp index 9b9e6e88ab..ab63444073 100644 --- a/src/gromacs/fileio/md5.cpp +++ b/src/gromacs/fileio/md5.cpp @@ -212,7 +212,7 @@ md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/) if (!((data - reinterpret_cast(0)) & 3)) { /* data are properly aligned */ - X = (const md5_word_t *)data; + X = reinterpret_cast(data); } else { @@ -378,7 +378,7 @@ gmx_md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes) const md5_byte_t *p = data; int left = nbytes; int offset = (pms->count[0] >> 3) & 63; - md5_word_t nbits = (md5_word_t)(nbytes << 3); + md5_word_t nbits = static_cast(nbytes << 3); if (nbytes <= 0) { @@ -436,7 +436,7 @@ gmx_md5_finish(md5_state_t *pms, md5_byte_t digest[16]) /* Save the length before padding. */ for (i = 0; i < 8; ++i) { - data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3)); + data[i] = static_cast(pms->count[i >> 2] >> ((i & 3) << 3)); } /* Pad to 56 bytes mod 64. */ gmx_md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1); @@ -444,6 +444,6 @@ gmx_md5_finish(md5_state_t *pms, md5_byte_t digest[16]) gmx_md5_append(pms, data, 8); for (i = 0; i < 16; ++i) { - digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3)); + digest[i] = static_cast(pms->abcd[i >> 2] >> ((i & 3) << 3)); } } diff --git a/src/gromacs/fileio/pdbio.cpp b/src/gromacs/fileio/pdbio.cpp index 1b3fc05daa..9b79e6385f 100644 --- a/src/gromacs/fileio/pdbio.cpp +++ b/src/gromacs/fileio/pdbio.cpp @@ -310,7 +310,7 @@ void write_pdbfile_indexed(FILE *out, const char *title, gmx_conect conect, gmx_bool bTerSepChains, bool usePqrFormat) { - gmx_conect_t *gc = (gmx_conect_t *)conect; + gmx_conect_t *gc = static_cast(conect); char resnm[6], nm[6]; int i, ii; int resind, resnr; @@ -840,7 +840,7 @@ static void gmx_conect_addline(gmx_conect_t *con, char *line) void gmx_conect_dump(FILE *fp, gmx_conect conect) { - gmx_conect_t *gc = (gmx_conect_t *)conect; + gmx_conect_t *gc = static_cast(conect); int i; for (i = 0; (i < gc->nconect); i++) @@ -889,7 +889,7 @@ gmx_bool gmx_conect_exist(gmx_conect conect, int ai, int aj) void gmx_conect_add(gmx_conect conect, int ai, int aj) { - gmx_conect_t *gc = (gmx_conect_t *)conect; + gmx_conect_t *gc = static_cast(conect); /* if (!gc->bSorted) sort_conect(gc);*/ diff --git a/src/gromacs/fileio/tngio.cpp b/src/gromacs/fileio/tngio.cpp index 268b4fbd42..1df209b639 100644 --- a/src/gromacs/fileio/tngio.cpp +++ b/src/gromacs/fileio/tngio.cpp @@ -874,7 +874,7 @@ void gmx_fwrite_tng(gmx_tng_trajectory_t gmx_tng, } tng_num_particles_get(tng, &nParticles); - if (nAtoms != (int)nParticles) + if (nAtoms != static_cast(nParticles)) { tng_implicit_num_particles_set(tng, nAtoms); } @@ -1539,7 +1539,7 @@ gmx_bool gmx_read_next_tng_frame(gmx_tng_trajectory_t gmx_tng_input, case TNG_TRAJ_VELOCITIES: srenew(fr->v, fr->natoms); convert_array_to_real_array(values, - (real *) fr->v, + reinterpret_cast(fr->v), getDistanceScaleFactor(gmx_tng_input), fr->natoms, DIM, @@ -1635,11 +1635,11 @@ void gmx_print_tng_molecule_system(gmx_tng_trajectory_t gmx_tng_input, tng_molecule_name_get(input, molecule, str, 256); if (varNAtoms == TNG_CONSTANT_N_ATOMS) { - if ((int)molCntList[i] == 0) + if (static_cast(molCntList[i]) == 0) { continue; } - fprintf(stream, "Molecule: %s, count: %d\n", str, (int)molCntList[i]); + fprintf(stream, "Molecule: %s, count: %d\n", str, static_cast(molCntList[i])); } else { diff --git a/src/gromacs/fileio/trxio.cpp b/src/gromacs/fileio/trxio.cpp index b4ce57ed8a..d7e37cdd4e 100644 --- a/src/gromacs/fileio/trxio.cpp +++ b/src/gromacs/fileio/trxio.cpp @@ -107,7 +107,7 @@ gmx_bool bRmod_fd(double a, double b, double c, gmx_bool bDouble) tol = 2*(bDouble ? GMX_DOUBLE_EPS : GMX_FLOAT_EPS); - iq = (int)((a - b + tol*a)/c); + iq = static_cast((a - b + tol*a)/c); return fabs(a - b - c*iq) <= tol*fabs(a); } @@ -226,7 +226,7 @@ int prec2ndec(real prec) gmx_fatal(FARGS, "DEATH HORROR prec (%g) <= 0 in prec2ndec", prec); } - return (int)(log(prec)/log(10.0)+0.5); + return static_cast(log(prec)/log(10.0)+0.5); } real ndec2prec(int ndec) diff --git a/src/gromacs/fileio/vmdio.cpp b/src/gromacs/fileio/vmdio.cpp index cc42a28af7..4b587df7ef 100644 --- a/src/gromacs/fileio/vmdio.cpp +++ b/src/gromacs/fileio/vmdio.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2009,2010,2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by + * Copyright (c) 2009,2010,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -129,7 +129,7 @@ static int register_cb(void *v, vmdplugin_t *p) if (strcmp(key, vmdplugin->filetype) == 0) { - vmdplugin->api = (molfile_plugin_t *)p; + vmdplugin->api = reinterpret_cast(p); } return VMDPLUGIN_SUCCESS; } @@ -149,7 +149,7 @@ static int load_sharedlibrary_plugins(const char *fullpath, gmx_vmdplugin_t *vmd } ifunc = vmddlsym(handle, "vmdplugin_init"); - if (!ifunc || ((initfunc)(ifunc))()) + if (!ifunc || (reinterpret_cast(ifunc))()) { printf("\nvmdplugin_init() for %s returned an error; plugin(s) not loaded.\n", fullpath); vmddlclose(handle); @@ -166,7 +166,7 @@ static int load_sharedlibrary_plugins(const char *fullpath, gmx_vmdplugin_t *vmd else { /* Load plugins from the library.*/ - ((regfunc)registerfunc)(vmdplugin, register_cb); + (reinterpret_cast(registerfunc))(vmdplugin, register_cb); } /* in case this library does not support the filetype, close it */ @@ -195,10 +195,10 @@ gmx_bool read_next_vmd_frame(gmx_vmdplugin_t *vmdplugin, t_trxframe *fr) snew(ts.velocities, fr->natoms*3); } #else - ts.coords = (float*)fr->x; + ts.coords = reinterpret_cast(fr->x); if (fr->bV) { - ts.velocities = (float*)fr->v; + ts.velocities = reinterpret_cast(fr->v); } #endif diff --git a/src/gromacs/fileio/writeps.cpp b/src/gromacs/fileio/writeps.cpp index 761036da75..9a7f29c056 100644 --- a/src/gromacs/fileio/writeps.cpp +++ b/src/gromacs/fileio/writeps.cpp @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2013,2014,2015,2017, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -228,10 +228,10 @@ void ps_line(t_psdata ps, real x1, real y1, real x2, real y2) static void do_box(t_psdata ps, real x1, real y1, real x2, real y2) { ps_moveto(ps, x1, y1); - ps_linerel(ps, 0, (real)(y2-y1)); - ps_linerel(ps, (real)(x2-x1), 0); - ps_linerel(ps, 0, (real)(y1-y2)); - ps_linerel(ps, (real)(x1-x2), 0); + ps_linerel(ps, 0, static_cast(y2-y1)); + ps_linerel(ps, static_cast(x2-x1), 0); + ps_linerel(ps, 0, static_cast(y1-y2)); + ps_linerel(ps, static_cast(x1-x2), 0); } void ps_box(t_psdata ps, real x1, real y1, real x2, real y2) diff --git a/src/gromacs/fileio/xdrd.cpp b/src/gromacs/fileio/xdrd.cpp index cceda7c302..d657619931 100644 --- a/src/gromacs/fileio/xdrd.cpp +++ b/src/gromacs/fileio/xdrd.cpp @@ -53,7 +53,7 @@ int xdr_real(XDR *xdrs, real *r) return ret; #else - return xdr_float(xdrs, (float *)r); + return xdr_float(xdrs, static_cast(r)); #endif } diff --git a/src/gromacs/fileio/xtcio.cpp b/src/gromacs/fileio/xtcio.cpp index 86bd6027b7..13c3365a9d 100644 --- a/src/gromacs/fileio/xtcio.cpp +++ b/src/gromacs/fileio/xtcio.cpp @@ -69,7 +69,7 @@ static int xdr_r2f(XDR *xdrs, real *r, gmx_bool gmx_unused bRead) return ret; #else - return xdr_float(xdrs, (float *)r); + return xdr_float(xdrs, static_cast(r)); #endif } diff --git a/src/gromacs/fileio/xvgr.cpp b/src/gromacs/fileio/xvgr.cpp index 149ff854a5..01e8b13c99 100644 --- a/src/gromacs/fileio/xvgr.cpp +++ b/src/gromacs/fileio/xvgr.cpp @@ -888,7 +888,7 @@ real **read_xvg_time(const char *fn, val_nalloc[set] = over_alloc_small(n); srenew(val[set], val_nalloc[set]); } - val[set][n] = (real)dbl; + val[set][n] = static_cast(dbl); } } a++; @@ -934,7 +934,7 @@ real **read_xvg_time(const char *fn, } if (n > 1) { - *dt = (real)((*t)[n-1]-(*t)[0])/(n-1.0); + *dt = static_cast((*t)[n-1]-(*t)[0])/(n-1.0); } else { diff --git a/src/gromacs/gmxana/gmx_anadock.cpp b/src/gromacs/gmxana/gmx_anadock.cpp index 65a7d0e7e1..f108e95935 100644 --- a/src/gromacs/gmxana/gmx_anadock.cpp +++ b/src/gromacs/gmxana/gmx_anadock.cpp @@ -137,12 +137,12 @@ static gmx_bool bFreeSort = FALSE; static int pdbf_comp(const void *a, const void *b) { - t_pdbfile *pa, *pb; - real x; - int dc; + const t_pdbfile *pa, *pb; + real x; + int dc; - pa = *(t_pdbfile **)a; - pb = *(t_pdbfile **)b; + pa = *static_cast(a); + pb = *static_cast(b); dc = pa->cluster_id - pb->cluster_id; diff --git a/src/gromacs/gmxana/gmx_awh.cpp b/src/gromacs/gmxana/gmx_awh.cpp index 9b0f14d397..3751698121 100644 --- a/src/gromacs/gmxana/gmx_awh.cpp +++ b/src/gromacs/gmxana/gmx_awh.cpp @@ -430,7 +430,7 @@ AwhReader::AwhReader(const AwhParams *awhParams, { AwhBiasParams *awhBiasParams = &awhParams->awhBiasParams[k]; - int numSubBlocks = (int)block->sub[subblockStart].fval[0]; + int numSubBlocks = static_cast(block->sub[subblockStart].fval[0]); std::unique_ptr awhOutputFile(new OutputFile(opt2fn("-o", numFileOptions, filenames), "AWH", awhParams->numBias, k)); diff --git a/src/gromacs/gmxana/gmx_bar.cpp b/src/gromacs/gmxana/gmx_bar.cpp index dec2c4bf98..f7e1db88ea 100644 --- a/src/gromacs/gmxana/gmx_bar.cpp +++ b/src/gromacs/gmxana/gmx_bar.cpp @@ -2968,7 +2968,7 @@ static void read_edr_rawdh_block(samples_t **smp, int *ndu, t_enxblock *blk, /* make room for the data */ if (gmx::index(s->ndu_alloc) < s->ndu + blk->sub[2].nr) { - s->ndu_alloc += (s->ndu_alloc < (size_t)blk->sub[2].nr) ? + s->ndu_alloc += (s->ndu_alloc < static_cast(blk->sub[2].nr)) ? blk->sub[2].nr*2 : s->ndu_alloc; srenew(s->du_alloc, s->ndu_alloc); s->du = s->du_alloc; diff --git a/src/gromacs/gmxana/gmx_cluster.cpp b/src/gromacs/gmxana/gmx_cluster.cpp index f95a299f9d..20df5cf592 100644 --- a/src/gromacs/gmxana/gmx_cluster.cpp +++ b/src/gromacs/gmxana/gmx_cluster.cpp @@ -795,8 +795,8 @@ static rvec **read_whole_trj(const char *fn, int isize, const int index[], int s i++; } while (read_next_x(oenv, status, &t, x, box)); - fprintf(stderr, "Allocated %lu bytes for frames\n", - (unsigned long) (max_nf*isize*sizeof(**xx))); + fprintf(stderr, "Allocated %zu bytes for frames\n", + (max_nf*isize*sizeof(**xx))); fprintf(stderr, "Read %d frames from trajectory %s\n", i0, fn); *nframe = i0; sfree(x); diff --git a/src/gromacs/gmxana/gmx_density.cpp b/src/gromacs/gmxana/gmx_density.cpp index 918ebd6c4e..e750d1d694 100644 --- a/src/gromacs/gmxana/gmx_density.cpp +++ b/src/gromacs/gmxana/gmx_density.cpp @@ -74,7 +74,7 @@ typedef struct { static int compare(void *a, void *b) { t_electron *tmp1, *tmp2; - tmp1 = (t_electron *)a; tmp2 = (t_electron *)b; + tmp1 = static_cast(a); tmp2 = static_cast(b); return std::strcmp(tmp1->atomname, tmp2->atomname); } @@ -124,7 +124,7 @@ static int get_electrons(t_electron **eltab, const char *fn) /* sort the list */ fprintf(stderr, "Sorting list..\n"); qsort ((void*)*eltab, nr, sizeof(t_electron), - (int(*)(const void*, const void*))compare); + reinterpret_cast(compare)); return nr; } @@ -276,10 +276,9 @@ static void calc_electron_density(const char *fn, int **index, const int gnx[], sought.atomname = gmx_strdup(*(top->atoms.atomname[index[n][i]])); /* now find the number of electrons. This is not efficient. */ - found = (t_electron *) - bsearch((const void *)&sought, - (const void *)eltab, nr, sizeof(t_electron), - (int(*)(const void*, const void*))compare); + found = static_cast(bsearch((const void *)&sought, + (const void *)eltab, nr, sizeof(t_electron), + reinterpret_cast(compare))); if (found == nullptr) { diff --git a/src/gromacs/gmxana/gmx_dipoles.cpp b/src/gromacs/gmxana/gmx_dipoles.cpp index 94aea2f132..b6ac920a90 100644 --- a/src/gromacs/gmxana/gmx_dipoles.cpp +++ b/src/gromacs/gmxana/gmx_dipoles.cpp @@ -945,11 +945,11 @@ static void do_dip(const t_topology *top, int ePBC, real volume, snew(dipsp, gnx_tot); /* we need a dummy file for gnuplot */ - dip3d = (FILE *)gmx_ffopen("dummy.dat", "w"); + dip3d = gmx_ffopen("dummy.dat", "w"); fprintf(dip3d, "%f %f %f", 0.0, 0.0, 0.0); gmx_ffclose(dip3d); - dip3d = (FILE *)gmx_ffopen(fndip3d, "w"); + dip3d = gmx_ffopen(fndip3d, "w"); try { gmx::BinaryInformationSettings settings; diff --git a/src/gromacs/gmxana/gmx_do_dssp.cpp b/src/gromacs/gmxana/gmx_do_dssp.cpp index 1d62dd0502..a1e9c2a63c 100644 --- a/src/gromacs/gmxana/gmx_do_dssp.cpp +++ b/src/gromacs/gmxana/gmx_do_dssp.cpp @@ -355,7 +355,7 @@ static void analyse_ss(const char *outfile, t_matrix *mat, const char *ss_string snew(total, mat->nmap); snew(leg, mat->nmap+1); leg[0] = "Structure"; - for (s = 0; s < (size_t)mat->nmap; s++) + for (s = 0; s < static_cast(mat->nmap); s++) { leg[s+1] = gmx_strdup(map[s].desc); } @@ -384,7 +384,7 @@ static void analyse_ss(const char *outfile, t_matrix *mat, const char *ss_string xvgr_legend(fp, mat->nmap+1, leg, oenv); total_count = 0; - for (s = 0; s < (size_t)mat->nmap; s++) + for (s = 0; s < static_cast(mat->nmap); s++) { total[s] = 0; } diff --git a/src/gromacs/gmxana/gmx_msd.cpp b/src/gromacs/gmxana/gmx_msd.cpp index 6818ac2855..9f23157d2f 100644 --- a/src/gromacs/gmxana/gmx_msd.cpp +++ b/src/gromacs/gmxana/gmx_msd.cpp @@ -117,7 +117,7 @@ static t_corr *init_corr(int nrgrp, int type, int axis, real dim_factor, int i; snew(curr, 1); - curr->type = (msd_type)type; + curr->type = static_cast(type); curr->axis = axis; curr->ngrp = nrgrp; curr->nrestart = 0; diff --git a/src/gromacs/gmxana/gmx_order.cpp b/src/gromacs/gmxana/gmx_order.cpp index fe804b62e6..1c0ee1af42 100644 --- a/src/gromacs/gmxana/gmx_order.cpp +++ b/src/gromacs/gmxana/gmx_order.cpp @@ -637,7 +637,7 @@ static void calc_order(const char *fn, const int *index, int *a, rvec **order, z1 = x1[a[index[i-1]+j]][axis]; z2 = x1[a[index[i+1]+j]][axis]; z_ave = 0.5 * (z1 + z2); - slice = (int)((nslices*z_ave)/box[axis][axis]); + slice = static_cast((nslices*z_ave)/box[axis][axis]); while (slice < 0) { slice += nslices; diff --git a/src/gromacs/gmxana/gmx_trjconv.cpp b/src/gromacs/gmxana/gmx_trjconv.cpp index 43deb7c96e..f2e2125e59 100644 --- a/src/gromacs/gmxana/gmx_trjconv.cpp +++ b/src/gromacs/gmxana/gmx_trjconv.cpp @@ -523,7 +523,7 @@ static void do_trunc(const char *fn, real t0) { fprintf(stderr, "Do you REALLY want to truncate this trajectory (%s) at:\n" "frame %d, time %g, bytes %ld ??? (type YES if so)\n", - fn, j, t, (long int)fpos); + fn, j, t, static_cast(fpos)); if (1 != scanf("%s", yesno)) { gmx_fatal(FARGS, "Error reading user input"); @@ -1137,7 +1137,7 @@ int gmx_trjconv(int argc, char *argv[]) if (opt2bSet("-fr", NFILE, fnm)) { printf("Select groups of frame number indices:\n"); - rd_index(opt2fn("-fr", NFILE, fnm), 1, &nrfri, (int **)&frindex, &frname); + rd_index(opt2fn("-fr", NFILE, fnm), 1, &nrfri, &frindex, &frname); if (debug) { for (i = 0; i < nrfri; i++) diff --git a/src/gromacs/gmxana/gmx_tune_pme.cpp b/src/gromacs/gmxana/gmx_tune_pme.cpp index ac3a4a42ce..15e63965b3 100644 --- a/src/gromacs/gmxana/gmx_tune_pme.cpp +++ b/src/gromacs/gmxana/gmx_tune_pme.cpp @@ -1139,7 +1139,7 @@ static void cleanup(const t_filenm *fnm, int nfile, int k, int nnodes, for (i = 0; i < nfile; i++) { - opt = (char *)fnm[i].opt; + opt = const_cast(fnm[i].opt); if (std::strcmp(opt, "-p") == 0) { /* do nothing; keep this file */ @@ -1923,7 +1923,7 @@ static void create_command_line_snippets( /********************/ for (i = 0; i < nfile; i++) { - opt = (char *)fnm[i].opt; + opt = const_cast(fnm[i].opt); name = opt2fn(opt, nfile, fnm); /* Strbuf contains the options, now let's sort out where we need that */ @@ -2034,7 +2034,7 @@ static void couple_files_options(int nfile, t_filenm fnm[]) for (i = 0; i < nfile; i++) { - opt = (char *)fnm[i].opt; + opt = const_cast(fnm[i].opt); bSet = ((fnm[i].flag & ffSET) != 0); bBench = (0 == std::strncmp(opt, "-b", 2)); diff --git a/src/gromacs/gmxana/gmx_velacc.cpp b/src/gromacs/gmxana/gmx_velacc.cpp index f9b9f07120..c4e33254e5 100644 --- a/src/gromacs/gmxana/gmx_velacc.cpp +++ b/src/gromacs/gmxana/gmx_velacc.cpp @@ -362,7 +362,7 @@ int gmx_velacc(int argc, char *argv[]) if (opt2bSet("-os", NFILE, fnm)) { - calc_spectrum(counter/2, (real *) (c1[0]), (t1-t0)/2, opt2fn("-os", NFILE, fnm), + calc_spectrum(counter/2, (c1[0]), (t1-t0)/2, opt2fn("-os", NFILE, fnm), oenv, bRecip); do_view(oenv, opt2fn("-os", NFILE, fnm), "-nxy"); } diff --git a/src/gromacs/gmxana/sfactor.cpp b/src/gromacs/gmxana/sfactor.cpp index 14d903e616..4432f90606 100644 --- a/src/gromacs/gmxana/sfactor.cpp +++ b/src/gromacs/gmxana/sfactor.cpp @@ -104,7 +104,7 @@ extern int * create_indexed_atom_type (reduced_atom_t * atm, int size) */ int *index_atp, i, i_tmp, j; - reduced_atom *att = (reduced_atom *)atm; + reduced_atom *att = static_cast(atm); snew (index_atp, 1); i_tmp = 1; @@ -163,8 +163,8 @@ extern void compute_structure_factor (structure_factor_t * sft, matrix box, reduced_atom_t * red, int isize, real start_q, real end_q, int group, real **sf_table) { - structure_factor *sf = (structure_factor *)sft; - reduced_atom *redt = (reduced_atom *)red; + structure_factor *sf = static_cast(sft); + reduced_atom *redt = static_cast(red); t_complex ***tmpSF; rvec k_factor; @@ -330,7 +330,7 @@ extern gmx_structurefactors_t *gmx_structurefactors_init(const char *datfn) fclose(fp); - return (gmx_structurefactors_t *) gsf; + return static_cast(gsf); } @@ -341,7 +341,7 @@ extern void rearrange_atoms (reduced_atom_t * positions, t_trxframe *fr, const i { int i; - reduced_atom *pos = (reduced_atom *)positions; + reduced_atom *pos = static_cast(positions); if (flag) { @@ -375,7 +375,7 @@ extern int return_atom_type (const char *name, gmx_structurefactors_t *gsf) int fndx = 0; int NCMT; - gmx_structurefactors *gsft = (gmx_structurefactors *)gsf; + gmx_structurefactors *gsft = static_cast(gsf); NCMT = gsft->nratoms; @@ -408,7 +408,7 @@ extern int return_atom_type (const char *name, gmx_structurefactors_t *gsf) nrc = 0; for (i = 0; i < cnt; i++) { - if (std::strlen(gsft->atomnm[tndx[i]]) > (size_t)nrc) + if (std::strlen(gsft->atomnm[tndx[i]]) > static_cast(nrc)) { nrc = std::strlen(gsft->atomnm[tndx[i]]); fndx = tndx[i]; @@ -424,7 +424,7 @@ extern int gmx_structurefactors_get_sf(gmx_structurefactors_t *gsf, int elem, re int success; int i; - gmx_structurefactors *gsft = (gmx_structurefactors *)gsf; + gmx_structurefactors *gsft = static_cast(gsf); success = 0; for (i = 0; i < 4; i++) @@ -519,7 +519,7 @@ extern int do_scattering_intensity (const char* fnTPS, const char* fnNDX, index_atp[i] = create_indexed_atom_type (red[i], isize[i]); } - sf_table = compute_scattering_factor_table (gmx_sf, (structure_factor_t *)sf); + sf_table = compute_scattering_factor_table (gmx_sf, static_cast(sf)); /* This is the main loop over frames */ @@ -531,14 +531,14 @@ extern int do_scattering_intensity (const char* fnTPS, const char* fnNDX, { rearrange_atoms (red[i], &fr, index[i], isize[i], &top, FALSE, gmx_sf); - compute_structure_factor ((structure_factor_t *)sf, box, red[i], isize[i], + compute_structure_factor (static_cast(sf), box, red[i], isize[i], start_q, end_q, i, sf_table); } } while (read_next_frame (oenv, status, &fr)); - save_data ((structure_factor_t *)sf, fnXVG, ng, start_q, end_q, oenv); + save_data (static_cast(sf), fnXVG, ng, start_q, end_q, oenv); sfree(a); @@ -558,7 +558,7 @@ extern void save_data (structure_factor_t *sft, const char *file, int ngrps, int i, g = 0; double *tmp, polarization_factor, A; - structure_factor *sf = (structure_factor *)sft; + structure_factor *sf = static_cast(sft); fp = xvgropen (file, "Scattering Intensity", "q (1/nm)", "Intensity (a.u.)", oenv); @@ -655,7 +655,7 @@ extern real **gmx_structurefactors_table(gmx_structurefactors_t *gsf, real momen int i, j; double q, sin_theta; real **sf_table; - gmx_structurefactors *gsft = (gmx_structurefactors *)gsf; + gmx_structurefactors *gsft = static_cast(gsf); NCMT = gsft->nratoms; nsftable = NCMT+3; @@ -688,7 +688,7 @@ extern void gmx_structurefactors_done(gmx_structurefactors_t *gsf) int i; gmx_structurefactors *sf; - sf = (gmx_structurefactors *) gsf; + sf = static_cast(gsf); for (i = 0; i < sf->nratoms; i++) { @@ -717,7 +717,7 @@ extern real **compute_scattering_factor_table (gmx_structurefactors_t *gsf, stru double hc = 1239.842; real ** sf_table; - structure_factor *sf = (structure_factor *)sft; + structure_factor *sf = static_cast(sft); /* \hbar \omega \lambda = hc = 1239.842 eV * nm */ diff --git a/src/gromacs/gmxlib/nonbonded/nonbonded.cpp b/src/gromacs/gmxlib/nonbonded/nonbonded.cpp index 002ef95e1c..dd1b6b3f4c 100644 --- a/src/gromacs/gmxlib/nonbonded/nonbonded.cpp +++ b/src/gromacs/gmxlib/nonbonded/nonbonded.cpp @@ -244,14 +244,14 @@ gmx_nonbonded_set_kernel_pointers(FILE *log, t_nblist *nl, gmx_bool bElecAndVdwS if (nl->type == GMX_NBLIST_INTERACTION_FREE_ENERGY) { - nl->kernelptr_vf = (void *) gmx_nb_free_energy_kernel; - nl->kernelptr_f = (void *) gmx_nb_free_energy_kernel; + nl->kernelptr_vf = reinterpret_cast(gmx_nb_free_energy_kernel); + nl->kernelptr_f = reinterpret_cast(gmx_nb_free_energy_kernel); nl->simd_padding_width = 1; } else if (!gmx_strcasecmp_min(geom, "CG-CG")) { - nl->kernelptr_vf = (void *) gmx_nb_generic_cg_kernel; - nl->kernelptr_f = (void *) gmx_nb_generic_cg_kernel; + nl->kernelptr_vf = reinterpret_cast(gmx_nb_generic_cg_kernel); + nl->kernelptr_f = reinterpret_cast(gmx_nb_generic_cg_kernel); nl->simd_padding_width = 1; } else @@ -260,18 +260,18 @@ gmx_nonbonded_set_kernel_pointers(FILE *log, t_nblist *nl, gmx_bool bElecAndVdwS for (i = 0; i < narch && nl->kernelptr_vf == nullptr; i++) { - nl->kernelptr_vf = (void *) nb_kernel_list_findkernel(log, arch_and_padding[i].arch, elec, elec_mod, vdw, vdw_mod, geom, other, "PotentialAndForce"); + nl->kernelptr_vf = reinterpret_cast(nb_kernel_list_findkernel(log, arch_and_padding[i].arch, elec, elec_mod, vdw, vdw_mod, geom, other, "PotentialAndForce")); nl->simd_padding_width = arch_and_padding[i].simd_padding_width; } for (i = 0; i < narch && nl->kernelptr_f == nullptr; i++) { - nl->kernelptr_f = (void *) nb_kernel_list_findkernel(log, arch_and_padding[i].arch, elec, elec_mod, vdw, vdw_mod, geom, other, "Force"); + nl->kernelptr_f = reinterpret_cast(nb_kernel_list_findkernel(log, arch_and_padding[i].arch, elec, elec_mod, vdw, vdw_mod, geom, other, "Force")); nl->simd_padding_width = arch_and_padding[i].simd_padding_width; /* If there is not force-only optimized kernel, is there a potential & force one? */ if (nl->kernelptr_f == nullptr) { - nl->kernelptr_f = (void *) nb_kernel_list_findkernel(nullptr, arch_and_padding[i].arch, elec, elec_mod, vdw, vdw_mod, geom, other, "PotentialAndForce"); + nl->kernelptr_f = reinterpret_cast(nb_kernel_list_findkernel(nullptr, arch_and_padding[i].arch, elec, elec_mod, vdw, vdw_mod, geom, other, "PotentialAndForce")); nl->simd_padding_width = arch_and_padding[i].simd_padding_width; } } @@ -301,8 +301,8 @@ gmx_nonbonded_set_kernel_pointers(FILE *log, t_nblist *nl, gmx_bool bElecAndVdwS */ if (nl->kernelptr_vf == nullptr && !gmx_strcasecmp_min(geom, "Particle-Particle")) { - nl->kernelptr_vf = (void *) gmx_nb_generic_kernel; - nl->kernelptr_f = (void *) gmx_nb_generic_kernel; + nl->kernelptr_vf = reinterpret_cast(gmx_nb_generic_kernel); + nl->kernelptr_f = reinterpret_cast(gmx_nb_generic_kernel); nl->simd_padding_width = 1; if (debug) { @@ -405,12 +405,12 @@ void do_nonbonded(const t_forcerec *fr, if (flags & GMX_NONBONDED_DO_POTENTIAL) { /* Potential and force */ - kernelptr = (nb_kernel_t *)nlist[i].kernelptr_vf; + kernelptr = reinterpret_cast(nlist[i].kernelptr_vf); } else { /* Force only, no potential */ - kernelptr = (nb_kernel_t *)nlist[i].kernelptr_f; + kernelptr = reinterpret_cast(nlist[i].kernelptr_f); } if (nlist[i].type != GMX_NBLIST_INTERACTION_FREE_ENERGY && (flags & GMX_NONBONDED_DO_FOREIGNLAMBDA)) diff --git a/src/gromacs/gmxpreprocess/convparm.cpp b/src/gromacs/gmxpreprocess/convparm.cpp index c6e2f3ccbc..ff4a568384 100644 --- a/src/gromacs/gmxpreprocess/convparm.cpp +++ b/src/gromacs/gmxpreprocess/convparm.cpp @@ -63,11 +63,11 @@ static int round_check(real r, int limit, int ftype, const char *name) if (r >= 0) { - i = (int)(r + 0.5); + i = static_cast(r + 0.5); } else { - i = (int)(r - 0.5); + i = static_cast(r - 0.5); } if (r-i > 0.01 || r-i < -0.01) @@ -473,7 +473,7 @@ static int enter_params(gmx_ffparams_t *ffparams, t_functype ftype, { if (ffparams->functype[type] == ftype) { - if (memcmp(&newparam, &ffparams->iparams[type], (size_t)sizeof(newparam)) == 0) + if (memcmp(&newparam, &ffparams->iparams[type], static_cast(sizeof(newparam))) == 0) { return type; } @@ -484,7 +484,7 @@ static int enter_params(gmx_ffparams_t *ffparams, t_functype ftype, { type = ffparams->ntypes; } - memcpy(&ffparams->iparams[type], &newparam, (size_t)sizeof(newparam)); + memcpy(&ffparams->iparams[type], &newparam, static_cast(sizeof(newparam))); ffparams->ntypes++; ffparams->functype[type] = ftype; @@ -558,9 +558,9 @@ void convert_params(int atnr, t_params nbtypes[], ffp->iparams = nullptr; ffp->reppow = reppow; - enter_function(&(nbtypes[F_LJ]), (t_functype)F_LJ, comb, reppow, ffp, nullptr, + enter_function(&(nbtypes[F_LJ]), static_cast(F_LJ), comb, reppow, ffp, nullptr, &maxtypes, TRUE, TRUE); - enter_function(&(nbtypes[F_BHAM]), (t_functype)F_BHAM, comb, reppow, ffp, nullptr, + enter_function(&(nbtypes[F_BHAM]), static_cast(F_BHAM), comb, reppow, ffp, nullptr, &maxtypes, TRUE, TRUE); for (size_t mt = 0; mt < mtop->moltype.size(); mt++) @@ -578,7 +578,7 @@ void convert_params(int atnr, t_params nbtypes[], (flags & IF_VSITE) || (flags & IF_CONSTRAINT))) { - enter_function(&(plist[i]), (t_functype)i, comb, reppow, + enter_function(&(plist[i]), static_cast(i), comb, reppow, ffp, &molt->ilist[i], &maxtypes, FALSE, (i == F_POSRES || i == F_FBPOSRES)); } @@ -620,7 +620,7 @@ void convert_params(int atnr, t_params nbtypes[], } else { - enter_function(&(plist[i]), (t_functype)i, comb, reppow, + enter_function(&(plist[i]), static_cast(i), comb, reppow, ffp, &mtop->intermolecular_ilist[i], &maxtypes, FALSE, FALSE); diff --git a/src/gromacs/gmxpreprocess/fflibutil.cpp b/src/gromacs/gmxpreprocess/fflibutil.cpp index 555bf9b09a..f8897302e2 100644 --- a/src/gromacs/gmxpreprocess/fflibutil.cpp +++ b/src/gromacs/gmxpreprocess/fflibutil.cpp @@ -82,7 +82,7 @@ void fflib_filename_base(const char *filename, char *filebase, int maxlen) { cptr = filename; } - if (strlen(filename) >= (size_t)maxlen) + if (strlen(filename) >= static_cast(maxlen)) { gmx_fatal(FARGS, "filename is longer (%zu) than maxlen (%d)", strlen(filename), maxlen); diff --git a/src/gromacs/gmxpreprocess/gen_ad.cpp b/src/gromacs/gmxpreprocess/gen_ad.cpp index 581f17d117..dcdeba3607 100644 --- a/src/gromacs/gmxpreprocess/gen_ad.cpp +++ b/src/gromacs/gmxpreprocess/gen_ad.cpp @@ -310,7 +310,7 @@ static int idcomp(const void *a, const void *b) } else { - return (int) (pa->a[2]-pb->a[2]); + return (pa->a[2]-pb->a[2]); } } @@ -330,7 +330,7 @@ static void sort_id(int nr, t_param ps[]) /* Now sort it */ if (nr > 1) { - qsort(ps, nr, (size_t)sizeof(ps[0]), idcomp); + qsort(ps, nr, static_cast(sizeof(ps[0])), idcomp); } } @@ -347,7 +347,7 @@ static int n_hydro(const int a[], char ***atomname) { nh++; } - else if (((int)strlen(aname) > 1) && (c0 >= '0') && (c0 <= '9')) + else if ((static_cast(strlen(aname)) > 1) && (c0 >= '0') && (c0 <= '9')) { c1 = toupper(aname[1]); if (c1 == 'H') @@ -625,7 +625,7 @@ static void gen_excls(t_atoms *atoms, t_excls *excls, t_hackblock hb[], { if (excls[a].nr > 1) { - qsort(excls[a].e, excls[a].nr, (size_t)sizeof(int), int_comp); + qsort(excls[a].e, excls[a].nr, static_cast(sizeof(int)), int_comp); } } } @@ -1098,19 +1098,19 @@ void gen_pad(t_nextnb *nnb, t_atoms *atoms, t_restp rtp[], /* Sort angles with respect to j-i-k (middle atom first) */ if (nang > 1) { - qsort(ang, nang, (size_t)sizeof(ang[0]), acomp); + qsort(ang, nang, static_cast(sizeof(ang[0])), acomp); } /* Sort dihedrals with respect to j-k-i-l (middle atoms first) */ if (ndih > 1) { - qsort(dih, ndih, (size_t)sizeof(dih[0]), dcomp); + qsort(dih, ndih, static_cast(sizeof(dih[0])), dcomp); } /* Sort the pairs */ if (npai > 1) { - qsort(pai, npai, (size_t)sizeof(pai[0]), pcomp); + qsort(pai, npai, static_cast(sizeof(pai[0])), pcomp); } if (npai > 0) { diff --git a/src/gromacs/gmxpreprocess/genconf.cpp b/src/gromacs/gmxpreprocess/genconf.cpp index c38392663a..70849f1e64 100644 --- a/src/gromacs/gmxpreprocess/genconf.cpp +++ b/src/gromacs/gmxpreprocess/genconf.cpp @@ -169,9 +169,9 @@ int gmx_genconf(int argc, char *argv[]) gmx::DefaultRandomEngine rng(seed); bTRX = ftp2bSet(efTRX, NFILE, fnm); - nx = (int)(nrbox[XX]+0.5); - ny = (int)(nrbox[YY]+0.5); - nz = (int)(nrbox[ZZ]+0.5); + nx = static_cast(nrbox[XX]+0.5); + ny = static_cast(nrbox[YY]+0.5); + nz = static_cast(nrbox[ZZ]+0.5); if ((nx <= 0) || (ny <= 0) || (nz <= 0)) { diff --git a/src/gromacs/gmxpreprocess/gmxcpp.cpp b/src/gromacs/gmxpreprocess/gmxcpp.cpp index 15eb3b997d..a771394479 100644 --- a/src/gromacs/gmxpreprocess/gmxcpp.cpp +++ b/src/gromacs/gmxpreprocess/gmxcpp.cpp @@ -361,7 +361,7 @@ int cpp_open_file(const char *filenm, gmx_cpp_t *handle, char **cppopts) static int process_directive(gmx_cpp_t *handlep, const char *dname, const char *dval) { - gmx_cpp_t handle = (gmx_cpp_t)*handlep; + gmx_cpp_t handle = *handlep; int i, i0, len, status; unsigned int i1; char *inc_fn, *name; @@ -567,7 +567,7 @@ process_directive(gmx_cpp_t *handlep, const char *dname, const char *dval) recursively and no cpp directives are printed. */ int cpp_read_line(gmx_cpp_t *handlep, int n, char buf[]) { - gmx_cpp_t handle = (gmx_cpp_t)*handlep; + gmx_cpp_t handle = *handlep; int i, nn, len, status; const char *ptr, *ptr2; char *name; @@ -669,7 +669,7 @@ int cpp_read_line(gmx_cpp_t *handlep, int n, char buf[]) ptr = buf; while ((ptr2 = strstrw(ptr, defs[i].name)) != nullptr) { - strncat(name, ptr, (int)(ptr2-ptr)); + strncat(name, ptr, static_cast(ptr2-ptr)); strcat(name, defs[i].def); ptr = ptr2 + strlen(defs[i].name); } @@ -696,7 +696,7 @@ int cpp_cur_linenr(const gmx_cpp_t *handlep) /* Close the file! Return integer status. */ int cpp_close_file(gmx_cpp_t *handlep) { - gmx_cpp_t handle = (gmx_cpp_t)*handlep; + gmx_cpp_t handle = *handlep; if (!handle) { @@ -773,11 +773,11 @@ char *cpp_error(gmx_cpp_t *handlep, int status) "Invalid file handle", "File not open", "Unknown error", "Error status out of range" }; - gmx_cpp_t handle = (gmx_cpp_t)*handlep; + gmx_cpp_t handle = *handlep; if (!handle) { - return (char *)ecpp[eCPP_INVALID_HANDLE]; + return const_cast(ecpp[eCPP_INVALID_HANDLE]); } if ((status < 0) || (status >= eCPP_NR)) diff --git a/src/gromacs/gmxpreprocess/gpp_bond_atomtype.cpp b/src/gromacs/gmxpreprocess/gpp_bond_atomtype.cpp index 2d79963270..ce31d32f8b 100644 --- a/src/gromacs/gmxpreprocess/gpp_bond_atomtype.cpp +++ b/src/gromacs/gmxpreprocess/gpp_bond_atomtype.cpp @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2011,2014,2015,2017, by the GROMACS development team, led by + * Copyright (c) 2011,2014,2015,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -52,7 +52,7 @@ typedef struct { int get_bond_atomtype_type(char *str, t_bond_atomtype at) { - gpp_bond_atomtype *ga = (gpp_bond_atomtype *) at; + gpp_bond_atomtype *ga = reinterpret_cast(at); int i; @@ -70,7 +70,7 @@ int get_bond_atomtype_type(char *str, t_bond_atomtype at) char *get_bond_atomtype_name(int nt, t_bond_atomtype at) { - gpp_bond_atomtype *ga = (gpp_bond_atomtype *) at; + gpp_bond_atomtype *ga = reinterpret_cast(at); if ((nt < 0) || (nt >= ga->nr)) { @@ -86,13 +86,13 @@ t_bond_atomtype init_bond_atomtype(void) snew(ga, 1); - return (t_bond_atomtype ) ga; + return reinterpret_cast(ga); } void add_bond_atomtype(t_bond_atomtype at, t_symtab *tab, char *name) { - gpp_bond_atomtype *ga = (gpp_bond_atomtype *) at; + gpp_bond_atomtype *ga = reinterpret_cast(at); ga->nr++; srenew(ga->atomname, ga->nr); @@ -101,7 +101,7 @@ void add_bond_atomtype(t_bond_atomtype at, t_symtab *tab, void done_bond_atomtype(t_bond_atomtype *at) { - gpp_bond_atomtype *ga = (gpp_bond_atomtype *) *at; + gpp_bond_atomtype *ga = reinterpret_cast(*at); sfree(ga->atomname); ga->nr = 0; diff --git a/src/gromacs/gmxpreprocess/gpp_nextnb.cpp b/src/gromacs/gmxpreprocess/gpp_nextnb.cpp index d567cdea34..47826b54f0 100644 --- a/src/gromacs/gmxpreprocess/gpp_nextnb.cpp +++ b/src/gromacs/gmxpreprocess/gpp_nextnb.cpp @@ -210,7 +210,7 @@ static void nnb2excl(t_nextnb *nnb, t_blocka *excl) prints("nnb2excl before qsort", nr_of_sortables, s); if (nr_of_sortables > 1) { - qsort ((void *)s, nr_of_sortables, (size_t)sizeof(s[0]), bond_sort); + qsort ((void *)s, nr_of_sortables, static_cast(sizeof(s[0])), bond_sort); prints("nnb2excl after qsort", nr_of_sortables, s); } @@ -391,7 +391,7 @@ void gen_nnb(t_nextnb *nnb, t_params plist[]) prints("gen_excl before qsort", nrbonds, s); if (nrbonds > 1) { - qsort((void *) s, nrbonds, (size_t)sizeof(sortable), bond_sort); + qsort((void *) s, nrbonds, static_cast(sizeof(sortable)), bond_sort); prints("gen_excl after qsort", nrbonds, s); } diff --git a/src/gromacs/gmxpreprocess/grompp.cpp b/src/gromacs/gmxpreprocess/grompp.cpp index 31ab064463..c3fe8e350d 100644 --- a/src/gromacs/gmxpreprocess/grompp.cpp +++ b/src/gromacs/gmxpreprocess/grompp.cpp @@ -2062,7 +2062,7 @@ int gmx_grompp(int argc, char *argv[]) else { sprintf(warn_buf, "NVE simulation with an initial temperature of zero: will use a Verlet buffer of %d%%. Check your energy drift!", - (int)(verlet_buffer_ratio_NVE_T0*100 + 0.5)); + static_cast(verlet_buffer_ratio_NVE_T0*100 + 0.5)); warning_note(wi, warn_buf); } } @@ -2100,8 +2100,8 @@ int gmx_grompp(int argc, char *argv[]) { sprintf(warn_buf, "You are using a Verlet buffer tolerance of %g kJ/mol/ps for an NVE simulation of length %g ps, which can give a final drift of %d%%. For conserving energy to %d%% when using constraints, you might need to set verlet-buffer-tolerance to %.1e.", ir->verletbuf_tol, ir->nsteps*ir->delta_t, - (int)(ir->verletbuf_tol/totalEnergyDriftPerAtomPerPicosecond*100 + 0.5), - (int)(100*driftTolerance + 0.5), + static_cast(ir->verletbuf_tol/totalEnergyDriftPerAtomPerPicosecond*100 + 0.5), + static_cast(100*driftTolerance + 0.5), driftTolerance*totalEnergyDriftPerAtomPerPicosecond); warning_note(wi, warn_buf); } diff --git a/src/gromacs/gmxpreprocess/h_db.cpp b/src/gromacs/gmxpreprocess/h_db.cpp index 52c634696d..d21ff1094f 100644 --- a/src/gromacs/gmxpreprocess/h_db.cpp +++ b/src/gromacs/gmxpreprocess/h_db.cpp @@ -188,7 +188,7 @@ static void read_h_db_file(const char *hfn, int *nahptr, t_hackblock **ah) if (nah > 0) { /* Sort the list (necessary to be able to use bsearch */ - qsort(aah, nah, (size_t)sizeof(**ah), compaddh); + qsort(aah, nah, static_cast(sizeof(**ah)), compaddh); } *nahptr = nah; @@ -228,7 +228,7 @@ t_hackblock *search_h_db(int nh, t_hackblock ah[], char *key) ahkey.name = key; - result = static_cast(bsearch(&ahkey, ah, nh, (size_t)sizeof(ah[0]), compaddh)); + result = static_cast(bsearch(&ahkey, ah, nh, static_cast(sizeof(ah[0])), compaddh)); return result; } diff --git a/src/gromacs/gmxpreprocess/pdb2gmx.cpp b/src/gromacs/gmxpreprocess/pdb2gmx.cpp index f2d8cb564c..49add7cf88 100644 --- a/src/gromacs/gmxpreprocess/pdb2gmx.cpp +++ b/src/gromacs/gmxpreprocess/pdb2gmx.cpp @@ -759,7 +759,7 @@ static void sort_pdbatoms(t_restp restp[], pdbi[i].anm1 = atomnm[1]; pdbi[i].altloc = pdba->pdbinfo[i].altloc; } - qsort(pdbi, natoms, (size_t)sizeof(pdbi[0]), pdbicomp); + qsort(pdbi, natoms, static_cast(sizeof(pdbi[0])), pdbicomp); /* pdba is sorted in pdbnew using the pdbi index */ snew(a, natoms); diff --git a/src/gromacs/gmxpreprocess/pdb2top.cpp b/src/gromacs/gmxpreprocess/pdb2top.cpp index 793eb0c666..913d227827 100644 --- a/src/gromacs/gmxpreprocess/pdb2top.cpp +++ b/src/gromacs/gmxpreprocess/pdb2top.cpp @@ -874,7 +874,7 @@ static void clean_bonds(t_params *ps) } /* Sort bonds */ - qsort(ps->param, ps->nr, (size_t)sizeof(ps->param[0]), pcompar); + qsort(ps->param, ps->nr, static_cast(sizeof(ps->param[0])), pcompar); /* remove doubles, keep the first one always. */ j = 1; diff --git a/src/gromacs/gmxpreprocess/pgutil.cpp b/src/gromacs/gmxpreprocess/pgutil.cpp index 89ca70ff6c..1dfd29551f 100644 --- a/src/gromacs/gmxpreprocess/pgutil.cpp +++ b/src/gromacs/gmxpreprocess/pgutil.cpp @@ -120,7 +120,7 @@ int search_atom(const char *type, int start, { if (anm[i] && gmx_strcasecmp(type, *(anm[i])) == 0) { - return (int) i; + return i; } } if (!(bNext && at[start].resind == at[natoms-1].resind)) @@ -140,7 +140,7 @@ int search_atom(const char *type, int start, { if (gmx_strcasecmp(type, *(anm[i])) == 0) { - return (int) i; + return i; } } if (start > 0) diff --git a/src/gromacs/gmxpreprocess/readir.cpp b/src/gromacs/gmxpreprocess/readir.cpp index 5e39a38bef..27e30adbcb 100644 --- a/src/gromacs/gmxpreprocess/readir.cpp +++ b/src/gromacs/gmxpreprocess/readir.cpp @@ -630,7 +630,7 @@ void check_ir(const char *mdparin, t_inputrec *ir, t_gromppopts *opts, CHECK(fep->sc_alpha != 0 && fep->sc_power != 1 && fep->sc_power != 2); sprintf(err_buf, "The soft-core sc-r-power is %d and can only be 6 or 48", - (int)fep->sc_r_power); + static_cast(fep->sc_r_power)); CHECK(fep->sc_alpha != 0 && fep->sc_r_power != 6.0 && fep->sc_r_power != 48.0); sprintf(err_buf, "Can't use positive delta-lambda (%g) if initial state/lambda does not start at zero", fep->delta_lambda); @@ -1492,7 +1492,7 @@ static void do_fep_params(t_inputrec *ir, char fep_lambda[][STRLEN], char weight { for (j = 0; j < fep->n_lambda; j++) { - fep->all_lambda[i][j] = (double)count_fep_lambdas[i][j]; + fep->all_lambda[i][j] = static_cast(count_fep_lambdas[i][j]); } sfree(count_fep_lambdas[i]); } @@ -1575,7 +1575,7 @@ static void do_fep_params(t_inputrec *ir, char fep_lambda[][STRLEN], char weight } if ((expand->nstexpanded < 0) && ir->bSimTemp) { - expand->nstexpanded = 2*(int)(ir->opts.tau_t[0]/ir->delta_t); + expand->nstexpanded = 2*static_cast(ir->opts.tau_t[0]/ir->delta_t); /* if you don't specify nstexpanded when doing expanded ensemble simulated tempering, it is set to 2*tau_t just to be careful so it's not to frequent */ } @@ -2978,7 +2978,7 @@ static void calc_nrdf(const gmx_mtop_t *mtop, t_inputrec *ir, char **gnames) { if (nrdf_vcm[j] > nrdf_vcm_sub[j]) { - nrdf_tc[i] += nrdf_uc*((double)na_vcm[j]/(double)na_tot)* + nrdf_tc[i] += nrdf_uc*(static_cast(na_vcm[j])/static_cast(na_tot))* (nrdf_vcm[j] - nrdf_vcm_sub[j])/nrdf_vcm[j]; } } diff --git a/src/gromacs/gmxpreprocess/resall.cpp b/src/gromacs/gmxpreprocess/resall.cpp index c87b8edba6..510525dcfa 100644 --- a/src/gromacs/gmxpreprocess/resall.cpp +++ b/src/gromacs/gmxpreprocess/resall.cpp @@ -547,8 +547,8 @@ static int neq_str_sign(const char *a1, const char *a2) { int l1, l2, lm; - l1 = (int)strlen(a1); - l2 = (int)strlen(a2); + l1 = static_cast(strlen(a1)); + l2 = static_cast(strlen(a2)); lm = std::min(l1, l2); if (lm >= 1 && @@ -586,8 +586,8 @@ char *search_rtp(const char *key, int nrtp, t_restp rtp[]) /* Allow a mismatch of at most a sign character (with warning) */ n = neq_str_sign(key, rtp[i].resname); if (n >= best && - n+1 >= (int)strlen(key) && - n+1 >= (int)strlen(rtp[i].resname)) + n+1 >= static_cast(strlen(key)) && + n+1 >= static_cast(strlen(rtp[i].resname))) { if (n == best) { diff --git a/src/gromacs/gmxpreprocess/topdirs.cpp b/src/gromacs/gmxpreprocess/topdirs.cpp index bd8bb4d093..a57275f2a0 100644 --- a/src/gromacs/gmxpreprocess/topdirs.cpp +++ b/src/gromacs/gmxpreprocess/topdirs.cpp @@ -310,9 +310,9 @@ directive str2dir (char *dstr) for (d = 0; (d < d_maxdir); d++) { - if (gmx_strcasecmp_min(ptr, dir2str((directive)d)) == 0) + if (gmx_strcasecmp_min(ptr, dir2str(static_cast(d))) == 0) { - return (directive)d; + return static_cast(d); } } @@ -331,7 +331,7 @@ static void set_nec(directive **n, ...) va_start(ap, n); do { - d = (directive)va_arg(ap, int); + d = static_cast(va_arg(ap, int)); srenew(*n, ++ind); (*n)[ind-1] = d; } diff --git a/src/gromacs/gmxpreprocess/topio.cpp b/src/gromacs/gmxpreprocess/topio.cpp index 1ff2a1ac5c..4354a3f05e 100644 --- a/src/gromacs/gmxpreprocess/topio.cpp +++ b/src/gromacs/gmxpreprocess/topio.cpp @@ -569,7 +569,7 @@ static char **read_topol(const char *infile, const char *outfile, trim (pline); /* if there is something left... */ - if ((int)strlen(pline) > 0) + if (static_cast(strlen(pline)) > 0) { if (pline[0] == OPENDIR) { @@ -891,7 +891,7 @@ static char **read_topol(const char *infile, const char *outfile, break; } default: - fprintf (stderr, "case: %d\n", (int)d); + fprintf (stderr, "case: %d\n", static_cast(d)); gmx_incons("unknown directive"); } } diff --git a/src/gromacs/gmxpreprocess/toppush.cpp b/src/gromacs/gmxpreprocess/toppush.cpp index 0826822335..8783264b18 100644 --- a/src/gromacs/gmxpreprocess/toppush.cpp +++ b/src/gromacs/gmxpreprocess/toppush.cpp @@ -2071,7 +2071,7 @@ void push_bond(directive d, t_params bondtype[], t_params bond[], { sprintf(errbuf, "%s table number can not be perturbed %d!=%d", interaction_function[ftype].longname, - (int)(param.c[0]+0.5), (int)(param.c[2]+0.5)); + static_cast(param.c[0]+0.5), static_cast(param.c[2]+0.5)); warning_error_and_exit(wi, errbuf, FARGS); } @@ -2525,7 +2525,7 @@ void merge_excl(t_blocka *excl, t_block2 *b2, warninp_t wi) if (b2->nra[i] > 0) { /* remove double entries */ - qsort(b2->a[i], (size_t)b2->nra[i], (size_t)sizeof(b2->a[i][0]), icomp); + qsort(b2->a[i], static_cast(b2->nra[i]), static_cast(sizeof(b2->a[i][0])), icomp); k = 1; for (j = 1; (j < b2->nra[i]); j++) { diff --git a/src/gromacs/gmxpreprocess/toputil.cpp b/src/gromacs/gmxpreprocess/toputil.cpp index 0b92f80ecd..5a38d4d7a1 100644 --- a/src/gromacs/gmxpreprocess/toputil.cpp +++ b/src/gromacs/gmxpreprocess/toputil.cpp @@ -372,7 +372,7 @@ void print_blocka(FILE *out, const char *szName, for (i = 0; (i < block->nr); i++) { fprintf (out, "%6d", i+1); - for (j = block->index[i]; (j < ((int)block->index[i+1])); j++) + for (j = block->index[i]; (j < (block->index[i+1])); j++) { fprintf (out, "%5d", block->a[j]+1); } @@ -499,7 +499,7 @@ void print_atoms(FILE *out, gpp_atomtype_t atype, t_atoms *at, int *cgnr, tpnmB, at->atom[i].qB, at->atom[i].mB); } // Accumulate the total charge to help troubleshoot issues. - qtot += (double)at->atom[i].q; + qtot += static_cast(at->atom[i].q); // Round it to zero if it is close to zero, because // printing -9.34e-5 confuses users. if (fabs(qtot) < 0.0001) diff --git a/src/gromacs/gmxpreprocess/x2top.cpp b/src/gromacs/gmxpreprocess/x2top.cpp index a92f0a9546..44d9061861 100644 --- a/src/gromacs/gmxpreprocess/x2top.cpp +++ b/src/gromacs/gmxpreprocess/x2top.cpp @@ -226,7 +226,7 @@ static void lo_set_force_const(t_params *plist, real c[], int nrfp, bool bRound, if (bDih) { c[0] *= c[2]; - c[0] = ((int)(c[0] + 3600)) % 360; + c[0] = (static_cast(c[0] + 3600)) % 360; if (c[0] > 180) { c[0] -= 360; diff --git a/src/gromacs/gmxpreprocess/xlate.cpp b/src/gromacs/gmxpreprocess/xlate.cpp index bf2a7d635a..44acfaae35 100644 --- a/src/gromacs/gmxpreprocess/xlate.cpp +++ b/src/gromacs/gmxpreprocess/xlate.cpp @@ -191,7 +191,7 @@ void rename_atoms(const char *xlfile, const char *ffdir, if (isdigit(atombuf[0])) { c = atombuf[0]; - for (i = 0; ((size_t)i < strlen(atombuf)-1); i++) + for (i = 0; (static_cast(i) < strlen(atombuf)-1); i++) { atombuf[i] = atombuf[i+1]; } diff --git a/src/gromacs/imd/imd.cpp b/src/gromacs/imd/imd.cpp index 764fe57a96..a9c9458e66 100644 --- a/src/gromacs/imd/imd.cpp +++ b/src/gromacs/imd/imd.cpp @@ -246,7 +246,7 @@ static const char *eIMDType_names[IMD_NR + 1] = { static void fill_header(IMDHeader *header, IMDMessageType type, int32_t length) { /* We (ab-)use htonl network function for the correct endianness */ - header->type = htonl((int32_t) type); + header->type = htonl(static_cast(type)); header->length = htonl(length); } @@ -335,7 +335,7 @@ static int imd_handshake(IMDSocket *socket) fill_header(&header, IMD_HANDSHAKE, 1); header.length = IMDVERSION; /* client wants unswapped version */ - return (imd_write_multiple(socket, (char *) &header, HEADERSIZE) != HEADERSIZE); + return (imd_write_multiple(socket, reinterpret_cast(&header), HEADERSIZE) != HEADERSIZE); } @@ -346,7 +346,7 @@ static int imd_send_energies(IMDSocket *socket, const IMDEnergyBlock *energies, recsize = HEADERSIZE + sizeof(IMDEnergyBlock); - fill_header((IMDHeader *) buffer, IMD_ENERGIES, 1); + fill_header(reinterpret_cast(buffer), IMD_ENERGIES, 1); memcpy(buffer + HEADERSIZE, energies, sizeof(IMDEnergyBlock)); return (imd_write_multiple(socket, buffer, recsize) != recsize); @@ -359,14 +359,14 @@ static IMDMessageType imd_recv_header(IMDSocket *socket, int32_t *length) IMDHeader header; - if (imd_read_multiple(socket, (char *) &header, HEADERSIZE) != HEADERSIZE) + if (imd_read_multiple(socket, reinterpret_cast(&header), HEADERSIZE) != HEADERSIZE) { return IMD_IOERROR; } swap_header(&header); *length = header.length; - return (IMDMessageType) header.type; + return static_cast(header.type); } @@ -381,7 +381,7 @@ static int imd_recv_mdcomm(IMDSocket *socket, int32_t nforces, int32_t *forcendx /* reading indices */ retsize = sizeof(int32_t) * nforces; - retbytes = imd_read_multiple(socket, (char *) forcendx, retsize); + retbytes = imd_read_multiple(socket, reinterpret_cast(forcendx), retsize); if (retbytes != retsize) { return FALSE; @@ -389,7 +389,7 @@ static int imd_recv_mdcomm(IMDSocket *socket, int32_t nforces, int32_t *forcendx /* reading forces as float array */ retsize = 3 * sizeof(float) * nforces; - retbytes = imd_read_multiple(socket, (char *) forces, retsize); + retbytes = imd_read_multiple(socket, reinterpret_cast(forces), retsize); if (retbytes != retsize) { return FALSE; @@ -450,12 +450,12 @@ static int imd_send_rvecs(IMDSocket *socket, int nat, rvec *x, char *buffer) size = HEADERSIZE + 3 * sizeof(float) * nat; /* Prepare header */ - fill_header((IMDHeader *) buffer, IMD_FCOORDS, (int32_t) nat); + fill_header(reinterpret_cast(buffer), IMD_FCOORDS, static_cast(nat)); for (i = 0; i < nat; i++) { - sendx[0] = (float) x[i][0] * NM2A; - sendx[1] = (float) x[i][1] * NM2A; - sendx[2] = (float) x[i][2] * NM2A; + sendx[0] = static_cast(x[i][0]) * NM2A; + sendx[1] = static_cast(x[i][1]) * NM2A; + sendx[2] = static_cast(x[i][2]) * NM2A; memcpy(buffer + HEADERSIZE + i * tuplesize, sendx, tuplesize); } @@ -618,7 +618,7 @@ static gmx_bool imd_tryconnect(t_gmx_IMD_setup *IMDsetup) static void imd_blockconnect(t_gmx_IMD_setup *IMDsetup) { /* do not wait for connection, when e.g. ctrl+c is pressed and we will terminate anyways. */ - if (!((int) gmx_get_stop_condition() == gmx_stop_cond_none)) + if (!(static_cast(gmx_get_stop_condition()) == gmx_stop_cond_none)) { return; } @@ -626,7 +626,7 @@ static void imd_blockconnect(t_gmx_IMD_setup *IMDsetup) fprintf(stderr, "%s Will wait until I have a connection and IMD_GO orders.\n", IMDstr); /* while we have no clientsocket... 2nd part: we should still react on ctrl+c */ - while ((!IMDsetup->clientsocket) && ((int) gmx_get_stop_condition() == gmx_stop_cond_none)) + while ((!IMDsetup->clientsocket) && (static_cast(gmx_get_stop_condition()) == gmx_stop_cond_none)) { imd_tryconnect(IMDsetup); #if GMX_NATIVE_WINDOWS @@ -966,7 +966,7 @@ static void imd_readcommand(t_gmx_IMD_setup *IMDsetup) /* Catch all rule for the remaining IMD types which we don't expect */ default: - fprintf(stderr, " %s Received unexpected %s.\n", IMDstr, enum_name((int)itype, IMD_NR, eIMDType_names)); + fprintf(stderr, " %s Received unexpected %s.\n", IMDstr, enum_name(static_cast(itype), IMD_NR, eIMDType_names)); imd_fatal(IMDsetup, "Terminating connection\n"); break; } /* end switch */ @@ -1582,15 +1582,15 @@ void IMD_fill_energy_record(gmx_bool bIMD, t_IMD *imd, gmx_enerdata_t *enerd, * last global communication step are still on display in the viewer. */ if (bHaveNewEnergies) { - ene->T_abs = (float) enerd->term[F_TEMP ]; - ene->E_pot = (float) enerd->term[F_EPOT ]; - ene->E_tot = (float) enerd->term[F_ETOT ]; - ene->E_bond = (float) enerd->term[F_BONDS ]; - ene->E_angle = (float) enerd->term[F_ANGLES ]; - ene->E_dihe = (float) enerd->term[F_PDIHS ]; - ene->E_impr = (float) enerd->term[F_IDIHS ]; - ene->E_vdw = (float) enerd->term[F_LJ ]; - ene->E_coul = (float) enerd->term[F_COUL_SR]; + ene->T_abs = static_cast(enerd->term[F_TEMP ]); + ene->E_pot = static_cast(enerd->term[F_EPOT ]); + ene->E_tot = static_cast(enerd->term[F_ETOT ]); + ene->E_bond = static_cast(enerd->term[F_BONDS ]); + ene->E_angle = static_cast(enerd->term[F_ANGLES ]); + ene->E_dihe = static_cast(enerd->term[F_PDIHS ]); + ene->E_impr = static_cast(enerd->term[F_IDIHS ]); + ene->E_vdw = static_cast(enerd->term[F_LJ ]); + ene->E_coul = static_cast(enerd->term[F_COUL_SR]); } } #else diff --git a/src/gromacs/imd/imdsocket.cpp b/src/gromacs/imd/imdsocket.cpp index afaa54dc9c..d5a5cfb418 100644 --- a/src/gromacs/imd/imdsocket.cpp +++ b/src/gromacs/imd/imdsocket.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2014,2015,2016,2017, by the GROMACS development team, led by + * Copyright (c) 2014,2015,2016,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -147,7 +147,7 @@ extern int imdsock_bind(IMDSocket *sock, int port) sock->address.sin_port = htons(port); /* Try to bind to address and port ...*/ - ret = bind(sock->sockfd, (struct sockaddr *) &sock->address, sizeof(sock->address)); + ret = bind(sock->sockfd, reinterpret_cast(&sock->address), sizeof(sock->address)); #else ret = -1; #endif @@ -191,7 +191,7 @@ extern IMDSocket* imdsock_accept(IMDSocket *sock) length = sizeof(sock->address); - ret = accept(sock->sockfd, (struct sockaddr *) &sock->address, &length); + ret = accept(sock->sockfd, reinterpret_cast(&sock->address), &length); /* successful, redirect to distinct clientsocket */ if (ret >= 0) @@ -222,7 +222,7 @@ extern int imdsock_getport(IMDSocket *sock, int *port) len = sizeof(struct sockaddr_in); - ret = getsockname(sock->sockfd, (struct sockaddr *) &(sock->address), &len); + ret = getsockname(sock->sockfd, reinterpret_cast(&(sock->address)), &len); if (ret) { fprintf(stderr, "%s getsockname failed with error %d.\n", IMDstr, ret); diff --git a/src/gromacs/listed-forces/listed-forces.cpp b/src/gromacs/listed-forces/listed-forces.cpp index 33ee488b6c..23dbbd1d41 100644 --- a/src/gromacs/listed-forces/listed-forces.cpp +++ b/src/gromacs/listed-forces/listed-forces.cpp @@ -367,7 +367,7 @@ calc_one_bond(int thread, /* No energies, shift forces, dvdl */ rbdihs_noener_simd(nbn, idef->il[ftype].iatoms+nb0, idef->iparams, - (const rvec*)x, f, + static_cast(x), f, pbc, g, lambda[efptFTYPE], md, fcd, global_atom_index); v = 0; diff --git a/src/gromacs/listed-forces/manage-threading.cpp b/src/gromacs/listed-forces/manage-threading.cpp index 8312e98d3c..82885e4af5 100644 --- a/src/gromacs/listed-forces/manage-threading.cpp +++ b/src/gromacs/listed-forces/manage-threading.cpp @@ -466,8 +466,8 @@ void setup_bonded_threading(bonded_threading_t *bt, fprintf(debug, "Number of %d atom blocks to reduce: %d\n", reduction_block_size, bt->nblock_used); fprintf(debug, "Reduction density %.2f for touched blocks only %.2f\n", - ctot*reduction_block_size/(double)numAtoms, - ctot/(double)bt->nblock_used); + ctot*reduction_block_size/static_cast(numAtoms), + ctot/static_cast(bt->nblock_used)); } } diff --git a/src/gromacs/math/invertmatrix.cpp b/src/gromacs/math/invertmatrix.cpp index 87100100d0..d4b3cefa1d 100644 --- a/src/gromacs/math/invertmatrix.cpp +++ b/src/gromacs/math/invertmatrix.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2015, by the GROMACS development team, led by + * Copyright (c) 2015,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -73,12 +73,12 @@ void invertBoxMatrix(const matrix src, matrix dest) void invertMatrix(const matrix src, matrix dest) { - const real smallreal = (real)1.0e-24; - const real largereal = (real)1.0e24; + const real smallreal = static_cast(1.0e-24); + const real largereal = static_cast(1.0e24); real determinant = det(src); - real c = (real)1.0/determinant; - real fc = (real)std::fabs(c); + real c = static_cast(1.0)/determinant; + real fc = static_cast(std::fabs(c)); if ((fc <= smallreal) || (fc >= largereal)) { diff --git a/src/gromacs/mdlib/calc_verletbuf.cpp b/src/gromacs/mdlib/calc_verletbuf.cpp index f40fbff9f4..56ab300b2b 100644 --- a/src/gromacs/mdlib/calc_verletbuf.cpp +++ b/src/gromacs/mdlib/calc_verletbuf.cpp @@ -714,11 +714,11 @@ static real energyDrift(const verletbuf_atomtype_t *att, int natt, /* Multiply by the number of atom pairs */ if (j == i) { - pot *= (double)att[i].n*(att[i].n - 1)/2; + pot *= static_cast(att[i].n)*(att[i].n - 1)/2; } else { - pot *= (double)att[i].n*att[j].n; + pot *= static_cast(att[i].n)*att[j].n; } /* We need the line density to get the energy drift of the system. * The effective average r^2 is close to (rlist+sigma)^2. @@ -1074,7 +1074,7 @@ void calc_verlet_buffer_size(const gmx_mtop_t *mtop, real boxvol, /* Search using bisection */ ib0 = -1; /* The drift will be neglible at 5 times the max sigma */ - ib1 = (int)(5*2*std::sqrt(kT_fac/mass_min)/resolution) + 1; + ib1 = static_cast(5*2*std::sqrt(kT_fac/mass_min)/resolution) + 1; while (ib1 - ib0 > 1) { ib = (ib0 + ib1)/2; diff --git a/src/gromacs/mdlib/calcmu.cpp b/src/gromacs/mdlib/calcmu.cpp index 8d04914175..f9d4979d9c 100644 --- a/src/gromacs/mdlib/calcmu.cpp +++ b/src/gromacs/mdlib/calcmu.cpp @@ -102,7 +102,7 @@ gmx_bool read_mu(FILE *fp, rvec mu, real *vol) /* For backward compatibility */ real mmm[4]; - if (fread(mmm, (size_t)(4*sizeof(real)), 1, fp) != 1) + if (fread(mmm, static_cast(4*sizeof(real)), 1, fp) != 1) { return FALSE; } diff --git a/src/gromacs/mdlib/coupling.cpp b/src/gromacs/mdlib/coupling.cpp index 3d2590d47e..061518a6b9 100644 --- a/src/gromacs/mdlib/coupling.cpp +++ b/src/gromacs/mdlib/coupling.cpp @@ -273,7 +273,7 @@ static void boxv_trotter(t_inputrec *ir, real *veta, real dt, tensor box, gmx_fatal(FARGS, "Barostat is coupled to a T-group with no degrees of freedom\n"); } /* alpha factor for phase space volume, then multiply by the ekin scaling factor. */ - alpha = 1.0 + DIM/((double)ir->opts.nrdf[0]); + alpha = 1.0 + DIM/(static_cast(ir->opts.nrdf[0])); alpha *= ekind->tcstat[0].ekinscalef_nhc; msmul(ekind->ekin, alpha, ekinmod); /* for now, we use Elr = 0, because if you want to get it right, you @@ -1450,7 +1450,7 @@ static real vrescale_sumnoises(real nn, int nn_int, i; real gauss; - nn_int = (int)(nn + 0.5); + nn_int = static_cast(nn + 0.5); if (nn - nn_int < -ndeg_tol || nn - nn_int > ndeg_tol) { diff --git a/src/gromacs/mdlib/ebin.cpp b/src/gromacs/mdlib/ebin.cpp index 0985f9e5dc..3096deb045 100644 --- a/src/gromacs/mdlib/ebin.cpp +++ b/src/gromacs/mdlib/ebin.cpp @@ -165,7 +165,7 @@ void add_ebin(t_ebin *eb, int index, int nener, const real ener[], gmx_bool bSum } else { - invmm = (1.0/(double)m)/((double)m+1.0); + invmm = (1.0/m)/(m+1.0); for (i = 0; (i < nener); i++) { diff --git a/src/gromacs/mdlib/expanded.cpp b/src/gromacs/mdlib/expanded.cpp index fe54c240d0..dc83030e60 100644 --- a/src/gromacs/mdlib/expanded.cpp +++ b/src/gromacs/mdlib/expanded.cpp @@ -212,7 +212,7 @@ static gmx_bool CheckHistogramRatios(int nhisto, const real *histo, real ratio) bIfFlat = FALSE; return bIfFlat; } - nmean /= (real)nhisto; + nmean /= static_cast(nhisto); bIfFlat = TRUE; for (i = 0; i < nhisto; i++) @@ -387,7 +387,7 @@ static gmx_bool UpdateWeights(int nlim, t_expanded *expand, df_history_t *dfhist GenerateGibbsProbabilities(weighted_lamee, p_k, &pks, 0, nlim-1); for (i = 0; i < nlim; i++) { - dfhist->wl_histo[i] += (real)p_k[i]; + dfhist->wl_histo[i] += static_cast(p_k[i]); } /* then increment weights (uses count) */ @@ -396,7 +396,7 @@ static gmx_bool UpdateWeights(int nlim, t_expanded *expand, df_history_t *dfhist for (i = 0; i < nlim; i++) { - dfhist->sum_weights[i] -= dfhist->wl_delta*(real)p_k[i]; + dfhist->sum_weights[i] -= dfhist->wl_delta*static_cast(p_k[i]); } /* Alternate definition, using logarithms. Shouldn't make very much difference! */ /* @@ -448,7 +448,7 @@ static gmx_bool UpdateWeights(int nlim, t_expanded *expand, df_history_t *dfhist for (nval = 0; nval < maxc; nval++) { /* constants for later use */ - cnval = (real)(nval-expand->c_range); + cnval = static_cast(nval-expand->c_range); /* actually, should be able to rewrite it w/o exponential, for better numerical stability */ if (fep_state > 0) { @@ -1063,7 +1063,7 @@ void PrintFreeEnergyInfoToFile(FILE *outfile, t_lambda *fep, t_expanded *expand, { if (expand->elamstats == elamstatsWL) { - fprintf(outfile, " %8d", (int)dfhist->wl_histo[ifep]); + fprintf(outfile, " %8d", static_cast(dfhist->wl_histo[ifep])); } else { @@ -1268,7 +1268,7 @@ int ExpandedEnsembleDynamics(FILE *log, t_inputrec *ir, gmx_enerdata_t *enerd, { if (log) { - fprintf(log, "\nStep %d: Weights have equilibrated, using criteria: %s\n", (int)step, elmceq_names[expand->elmceq]); + fprintf(log, "\nStep %" PRId64 ": Weights have equilibrated, using criteria: %s\n", step, elmceq_names[expand->elmceq]); } } @@ -1370,7 +1370,7 @@ int ExpandedEnsembleDynamics(FILE *log, t_inputrec *ir, gmx_enerdata_t *enerd, dfhist->wl_delta *= expand->wl_scale; if (log) { - fprintf(log, "\nStep %d: weights are now:", (int)step); + fprintf(log, "\nStep %d: weights are now:", static_cast(step)); for (i = 0; i < nlim; i++) { fprintf(log, " %.5f", dfhist->sum_weights[i]); diff --git a/src/gromacs/mdlib/forcerec.cpp b/src/gromacs/mdlib/forcerec.cpp index 6d2981d5e3..3d30bc8f40 100644 --- a/src/gromacs/mdlib/forcerec.cpp +++ b/src/gromacs/mdlib/forcerec.cpp @@ -1198,8 +1198,8 @@ void set_avcsixtwelve(FILE *fplog, t_forcerec *fr, const gmx_mtop_t *mtop) if (debug) { fprintf(debug, "Counted %d exclusions\n", nexcl); - fprintf(debug, "Average C6 parameter is: %10g\n", (double)csix); - fprintf(debug, "Average C12 parameter is: %10g\n", (double)ctwelve); + fprintf(debug, "Average C6 parameter is: %10g\n", csix); + fprintf(debug, "Average C12 parameter is: %10g\n", ctwelve); } fr->avcsix[q] = csix; fr->avctwelve[q] = ctwelve; diff --git a/src/gromacs/mdlib/md_support.cpp b/src/gromacs/mdlib/md_support.cpp index 3386196034..557e5cb014 100644 --- a/src/gromacs/mdlib/md_support.cpp +++ b/src/gromacs/mdlib/md_support.cpp @@ -271,7 +271,7 @@ void compute_globals(FILE *fplog, gmx_global_stat *gstat, t_commrec *cr, t_input */ enerd->term[F_TEMP] = sum_ekin(&(ir->opts), ekind, &dvdl_ekin, bEkinAveVel, bScaleEkin); - enerd->dvdl_lin[efptMASS] = (double) dvdl_ekin; + enerd->dvdl_lin[efptMASS] = static_cast(dvdl_ekin); enerd->term[F_EKIN] = trace(ekind->ekin); } diff --git a/src/gromacs/mdlib/mdebin.cpp b/src/gromacs/mdlib/mdebin.cpp index 4b7e98650e..64cfab7060 100644 --- a/src/gromacs/mdlib/mdebin.cpp +++ b/src/gromacs/mdlib/mdebin.cpp @@ -1195,7 +1195,7 @@ void upd_mdebin(t_mdebin *md, store_energy = enerd->term[F_ETOT]; /* store_dh is dE */ mde_delta_h_coll_add_dh(md->dhc, - (double)state->fep_state, + static_cast(state->fep_state), store_energy, pv, store_dhdl, diff --git a/src/gromacs/mdlib/mdebin_bar.cpp b/src/gromacs/mdlib/mdebin_bar.cpp index 3f578a1dc1..0597e8aaf9 100644 --- a/src/gromacs/mdlib/mdebin_bar.cpp +++ b/src/gromacs/mdlib/mdebin_bar.cpp @@ -176,7 +176,7 @@ static void mde_delta_h_make_hist(t_mde_delta_h *dh, int hi, gmx_bool invert) Get this start value in number of histogram dxs from zero, as an integer.*/ - dh->x0[hi] = (int64_t)floor(min_dh/dx); + dh->x0[hi] = static_cast(floor(min_dh/dx)); min_dh_hist = (dh->x0[hi])*dx; max_dh_hist = (dh->x0[hi] + dh->nbins + 1)*dx; @@ -192,7 +192,7 @@ static void mde_delta_h_make_hist(t_mde_delta_h *dh, int hi, gmx_bool invert) might lead to overflow with unpredictable results.*/ if ( (f*dh->dh[i] >= min_dh_hist) && (f*dh->dh[i] <= max_dh_hist ) ) { - bin = (unsigned int)( (f*dh->dh[i] - min_dh_hist)/dx ); + bin = static_cast( (f*dh->dh[i] - min_dh_hist)/dx ); } else { @@ -269,7 +269,7 @@ static void mde_delta_h_handle_block(t_mde_delta_h *dh, t_enxblock *blk) blk->sub[2].type = xdr_datatype_float; for (i = 0; i < dh->ndh; i++) { - dh->dhf[i] = (float)dh->dh[i]; + dh->dhf[i] = static_cast(dh->dh[i]); } blk->sub[2].fval = dh->dhf; dh->written = TRUE; diff --git a/src/gromacs/mdlib/membed.cpp b/src/gromacs/mdlib/membed.cpp index 1195178d8a..19edefaedd 100644 --- a/src/gromacs/mdlib/membed.cpp +++ b/src/gromacs/mdlib/membed.cpp @@ -446,7 +446,7 @@ static int init_mem_at(mem_t *mem_p, gmx_mtop_t *mtop, rvec *r, matrix box, pos_ /*membrane area within the box defined by the min and max coordinates of the embedded molecule*/ mem_area = (pos_ins->xmax[XX]-pos_ins->xmin[XX])*(pos_ins->xmax[YY]-pos_ins->xmin[YY]); /*rough estimate of area per lipid, assuming there is only one type of lipid in the membrane*/ - mem_p->lip_area = 2.0*mem_area/(double)nmolbox; + mem_p->lip_area = 2.0*mem_area/static_cast(nmolbox); return mem_p->mem_at.nr; } @@ -496,7 +496,7 @@ static void init_resize(t_block *ins_at, rvec *r_ins, pos_ins_t *pos_ins, mem_t if (c > 0) { - svmul(1/(double)c, pos_ins->geom_cent[i], pos_ins->geom_cent[i]); + svmul(1/static_cast(c), pos_ins->geom_cent[i], pos_ins->geom_cent[i]); } if (!bALLOW_ASYMMETRY) @@ -1227,7 +1227,7 @@ gmx_membed_t *init_membed(FILE *fplog, int nfile, const t_filenm fnm[], gmx_mtop "The area per lipid is %.4f nm^2.\n", mem_p->nmol, mem_p->lip_area); /* Maximum number of lipids to be removed*/ - max_lip_rm = (int)(2*prot_area/mem_p->lip_area); + max_lip_rm = static_cast(2*prot_area/mem_p->lip_area); printf("Maximum number of lipids that will be removed is %d.\n", max_lip_rm); printf("\nWill resize the protein by a factor of %.3f in the xy plane and %.3f in the z direction.\n" @@ -1241,8 +1241,8 @@ gmx_membed_t *init_membed(FILE *fplog, int nfile, const t_filenm fnm[], gmx_mtop membed->fac[0] = membed->fac[1] = xy_fac; membed->fac[2] = z_fac; - membed->xy_step = (xy_max-xy_fac)/(double)(it_xy); - membed->z_step = (z_max-z_fac)/(double)(it_z-1); + membed->xy_step = (xy_max-xy_fac)/static_cast(it_xy); + membed->z_step = (z_max-z_fac)/static_cast(it_z-1); resize(r_ins, as_rvec_array(state->x.data()), pos_ins, membed->fac); diff --git a/src/gromacs/mdlib/nbnxn_atomdata.cpp b/src/gromacs/mdlib/nbnxn_atomdata.cpp index 992c772695..42fa2ba3dd 100644 --- a/src/gromacs/mdlib/nbnxn_atomdata.cpp +++ b/src/gromacs/mdlib/nbnxn_atomdata.cpp @@ -120,36 +120,36 @@ void nbnxn_atomdata_realloc(nbnxn_atomdata_t *nbat, int n) int t; - nbnxn_realloc_void((void **)&nbat->type, + nbnxn_realloc_void(reinterpret_cast(&nbat->type), nbat->natoms*sizeof(*nbat->type), n*sizeof(*nbat->type), nbat->alloc, nbat->free); - nbnxn_realloc_void((void **)&nbat->lj_comb, + nbnxn_realloc_void(reinterpret_cast(&nbat->lj_comb), nbat->natoms*2*sizeof(*nbat->lj_comb), n*2*sizeof(*nbat->lj_comb), nbat->alloc, nbat->free); if (nbat->XFormat != nbatXYZQ) { - nbnxn_realloc_void((void **)&nbat->q, + nbnxn_realloc_void(reinterpret_cast(&nbat->q), nbat->natoms*sizeof(*nbat->q), n*sizeof(*nbat->q), nbat->alloc, nbat->free); } if (nbat->nenergrp > 1) { - nbnxn_realloc_void((void **)&nbat->energrp, + nbnxn_realloc_void(reinterpret_cast(&nbat->energrp), nbat->natoms/nbat->na_c*sizeof(*nbat->energrp), n/nbat->na_c*sizeof(*nbat->energrp), nbat->alloc, nbat->free); } - nbnxn_realloc_void((void **)&nbat->x, + nbnxn_realloc_void(reinterpret_cast(&nbat->x), nbat->natoms*nbat->xstride*sizeof(*nbat->x), n*nbat->xstride*sizeof(*nbat->x), nbat->alloc, nbat->free); for (t = 0; t < nbat->nout; t++) { /* Allocate one element extra for possible signaling with GPUs */ - nbnxn_realloc_void((void **)&nbat->out[t].f, + nbnxn_realloc_void(reinterpret_cast(&nbat->out[t].f), nbat->natoms*nbat->fstride*sizeof(*nbat->out[t].f), n*nbat->fstride*sizeof(*nbat->out[t].f), nbat->alloc, nbat->free); @@ -164,18 +164,18 @@ static void nbnxn_atomdata_output_init(nbnxn_atomdata_output_t *out, nbnxn_alloc_t *ma) { out->f = nullptr; - ma((void **)&out->fshift, SHIFTS*DIM*sizeof(*out->fshift)); + ma(reinterpret_cast(&out->fshift), SHIFTS*DIM*sizeof(*out->fshift)); out->nV = nenergrp*nenergrp; - ma((void **)&out->Vvdw, out->nV*sizeof(*out->Vvdw)); - ma((void **)&out->Vc, out->nV*sizeof(*out->Vc )); + ma(reinterpret_cast(&out->Vvdw), out->nV*sizeof(*out->Vvdw)); + ma(reinterpret_cast(&out->Vc), out->nV*sizeof(*out->Vc )); if (nb_kernel_type == nbnxnk4xN_SIMD_4xN || nb_kernel_type == nbnxnk4xN_SIMD_2xNN) { int cj_size = nbnxn_kernel_to_cluster_j_size(nb_kernel_type); out->nVS = nenergrp*nenergrp*stride*(cj_size>>1)*cj_size; - ma((void **)&out->VSvdw, out->nVS*sizeof(*out->VSvdw)); - ma((void **)&out->VSc, out->nVS*sizeof(*out->VSc )); + ma(reinterpret_cast(&out->VSvdw), out->nVS*sizeof(*out->VSvdw)); + ma(reinterpret_cast(&out->VSc), out->nVS*sizeof(*out->VSc )); } else { @@ -338,7 +338,7 @@ static void set_lj_parameter_data(nbnxn_atomdata_t *nbat, gmx_bool bSIMD) * when it might not be used, but introducing the conditional code is not * really worth it. */ - nbat->alloc((void **)&nbat->nbfp_aligned, + nbat->alloc(reinterpret_cast(&nbat->nbfp_aligned), nt*nt*c_simdBestPairAlignment*sizeof(*nbat->nbfp_aligned)); for (int i = 0; i < nt; i++) { @@ -523,9 +523,9 @@ void nbnxn_atomdata_init(const gmx::MDLogger &mdlog, fprintf(debug, "There are %d atom types in the system, adding one for nbnxn_atomdata_t\n", ntype); } nbat->ntype = ntype + 1; - nbat->alloc((void **)&nbat->nbfp, + nbat->alloc(reinterpret_cast(&nbat->nbfp), nbat->ntype*nbat->ntype*2*sizeof(*nbat->nbfp)); - nbat->alloc((void **)&nbat->nbfp_comb, nbat->ntype*2*sizeof(*nbat->nbfp_comb)); + nbat->alloc(reinterpret_cast(&nbat->nbfp_comb), nbat->ntype*2*sizeof(*nbat->nbfp_comb)); /* A tolerance of 1e-5 seems reasonable for (possibly hand-typed) * force-field floating point parameters. @@ -720,7 +720,7 @@ void nbnxn_atomdata_init(const gmx::MDLogger &mdlog, nbat->neg_2log++; } nbat->energrp = nullptr; - nbat->alloc((void **)&nbat->shift_vec, SHIFTS*sizeof(*nbat->shift_vec)); + nbat->alloc(reinterpret_cast(&nbat->shift_vec), SHIFTS*sizeof(*nbat->shift_vec)); nbat->xstride = (nbat->XFormat == nbatXYZQ ? STRIDE_XYZQ : DIM); nbat->fstride = (nbat->FFormat == nbatXYZQ ? STRIDE_XYZQ : DIM); nbat->x = nullptr; diff --git a/src/gromacs/mdlib/nbnxn_grid.cpp b/src/gromacs/mdlib/nbnxn_grid.cpp index 619347c0e2..13aaf12ee4 100644 --- a/src/gromacs/mdlib/nbnxn_grid.cpp +++ b/src/gromacs/mdlib/nbnxn_grid.cpp @@ -1285,7 +1285,7 @@ static void calc_cell_indices(nbnxn_search *nbs, { fprintf(debug, "ns na_sc %d na_c %d super-cells: %d x %d y %d z %.1f maxz %d\n", grid->na_sc, grid->na_c, grid->nc, - grid->numCells[XX], grid->numCells[YY], grid->nc/((double)(grid->numCells[XX]*grid->numCells[YY])), + grid->numCells[XX], grid->numCells[YY], grid->nc/(static_cast(grid->numCells[XX]*grid->numCells[YY])), ncz_max); if (gmx_debug_at) { @@ -1383,7 +1383,7 @@ static void calc_cell_indices(nbnxn_search *nbs, else { fprintf(debug, "ns non-zero sub-cells: %d average atoms %.2f\n", - grid->nsubc_tot, (atomEnd - atomStart)/(double)grid->nsubc_tot); + grid->nsubc_tot, (atomEnd - atomStart)/static_cast(grid->nsubc_tot)); print_bbsizes_supersub(debug, grid); } diff --git a/src/gromacs/mdlib/nbnxn_kernels/nbnxn_kernel_gpu_ref.cpp b/src/gromacs/mdlib/nbnxn_kernels/nbnxn_kernel_gpu_ref.cpp index 031c8e5815..11353d4720 100644 --- a/src/gromacs/mdlib/nbnxn_kernels/nbnxn_kernel_gpu_ref.cpp +++ b/src/gromacs/mdlib/nbnxn_kernels/nbnxn_kernel_gpu_ref.cpp @@ -370,7 +370,7 @@ nbnxn_kernel_gpu_ref(const nbnxn_pairlist_t *nbl, { fprintf(debug, "number of half %dx%d atom pairs: %d after pruning: %d fraction %4.2f\n", nbl->na_ci, nbl->na_ci, - nhwu, nhwu_pruned, nhwu_pruned/(double)nhwu); + nhwu, nhwu_pruned, nhwu_pruned/static_cast(nhwu)); fprintf(debug, "generic kernel pair interactions: %d\n", nhwu*nbl->na_ci/2*nbl->na_ci); fprintf(debug, "generic kernel post-prune pair interactions: %d\n", @@ -378,6 +378,6 @@ nbnxn_kernel_gpu_ref(const nbnxn_pairlist_t *nbl, fprintf(debug, "generic kernel non-zero pair interactions: %d\n", npair_tot); fprintf(debug, "ratio non-zero/post-prune pair interactions: %4.2f\n", - npair_tot/(double)(nhwu_pruned*gmx::exactDiv(nbl->na_ci, 2)*nbl->na_ci)); + npair_tot/static_cast(nhwu_pruned*gmx::exactDiv(nbl->na_ci, 2)*nbl->na_ci)); } } diff --git a/src/gromacs/mdlib/nbnxn_search.cpp b/src/gromacs/mdlib/nbnxn_search.cpp index 0248a5d1a5..81979e6431 100644 --- a/src/gromacs/mdlib/nbnxn_search.cpp +++ b/src/gromacs/mdlib/nbnxn_search.cpp @@ -93,7 +93,7 @@ static void nbs_cycle_clear(nbnxn_cycle_t *cc) static double Mcyc_av(const nbnxn_cycle_t *cc) { - return (double)cc->c*1e-6/cc->count; + return static_cast(cc->c)*1e-6/cc->count; } static void nbs_cycle_print(FILE *fp, const nbnxn_search *nbs) @@ -737,7 +737,7 @@ static void check_excl_space(nbnxn_pairlist_t *nbl, int extra) if (nbl->nexcl+extra > nbl->excl_nalloc) { nbl->excl_nalloc = over_alloc_small(nbl->nexcl+extra); - nbnxn_realloc_void((void **)&nbl->excl, + nbnxn_realloc_void(reinterpret_cast(&nbl->excl), nbl->nexcl*sizeof(*nbl->excl), nbl->excl_nalloc*sizeof(*nbl->excl), nbl->alloc, nbl->free); @@ -755,12 +755,12 @@ static void check_cell_list_space_simple(nbnxn_pairlist_t *nbl, if (cj_max > nbl->cj_nalloc) { nbl->cj_nalloc = over_alloc_small(cj_max); - nbnxn_realloc_void((void **)&nbl->cj, + nbnxn_realloc_void(reinterpret_cast(&nbl->cj), nbl->ncj*sizeof(*nbl->cj), nbl->cj_nalloc*sizeof(*nbl->cj), nbl->alloc, nbl->free); - nbnxn_realloc_void((void **)&nbl->cjOuter, + nbnxn_realloc_void(reinterpret_cast(&nbl->cjOuter), nbl->ncj*sizeof(*nbl->cjOuter), nbl->cj_nalloc*sizeof(*nbl->cjOuter), nbl->alloc, nbl->free); @@ -782,7 +782,7 @@ static void check_cell_list_space_supersub(nbnxn_pairlist_t *nbl, if (ncj4_max > nbl->cj4_nalloc) { nbl->cj4_nalloc = over_alloc_small(ncj4_max); - nbnxn_realloc_void((void **)&nbl->cj4, + nbnxn_realloc_void(reinterpret_cast(&nbl->cj4), nbl->work->cj4_init*sizeof(*nbl->cj4), nbl->cj4_nalloc*sizeof(*nbl->cj4), nbl->alloc, nbl->free); @@ -970,12 +970,12 @@ static void print_nblist_statistics_simple(FILE *fp, const nbnxn_pairlist_t *nbl fprintf(fp, "nbl nci %d ncj %d\n", nbl->nci, nbl->ncjInUse); fprintf(fp, "nbl na_sc %d rl %g ncp %d per cell %.1f atoms %.1f ratio %.2f\n", - nbl->na_sc, rl, nbl->ncjInUse, nbl->ncjInUse/(double)grid->nc, - nbl->ncjInUse/(double)grid->nc*grid->na_sc, - nbl->ncjInUse/(double)grid->nc*grid->na_sc/(0.5*4.0/3.0*M_PI*rl*rl*rl*grid->nc*grid->na_sc/(grid->size[XX]*grid->size[YY]*grid->size[ZZ]))); + nbl->na_sc, rl, nbl->ncjInUse, nbl->ncjInUse/static_cast(grid->nc), + nbl->ncjInUse/static_cast(grid->nc)*grid->na_sc, + nbl->ncjInUse/static_cast(grid->nc)*grid->na_sc/(0.5*4.0/3.0*M_PI*rl*rl*rl*grid->nc*grid->na_sc/(grid->size[XX]*grid->size[YY]*grid->size[ZZ]))); fprintf(fp, "nbl average j cell list length %.1f\n", - 0.25*nbl->ncjInUse/(double)std::max(nbl->nci, 1)); + 0.25*nbl->ncjInUse/static_cast(std::max(nbl->nci, 1))); for (int s = 0; s < SHIFTS; s++) { @@ -996,7 +996,7 @@ static void print_nblist_statistics_simple(FILE *fp, const nbnxn_pairlist_t *nbl } } fprintf(fp, "nbl cell pairs, total: %d excl: %d %.1f%%\n", - nbl->ncj, npexcl, 100*npexcl/(double)std::max(nbl->ncj, 1)); + nbl->ncj, npexcl, 100*npexcl/static_cast(std::max(nbl->ncj, 1))); for (int s = 0; s < SHIFTS; s++) { if (cs[s] > 0) @@ -1022,9 +1022,9 @@ static void print_nblist_statistics_supersub(FILE *fp, const nbnxn_pairlist_t *n fprintf(fp, "nbl nsci %d ncj4 %d nsi %d excl4 %d\n", nbl->nsci, nbl->ncj4, nbl->nci_tot, nbl->nexcl); fprintf(fp, "nbl na_c %d rl %g ncp %d per cell %.1f atoms %.1f ratio %.2f\n", - nbl->na_ci, rl, nbl->nci_tot, nbl->nci_tot/(double)grid->nsubc_tot, - nbl->nci_tot/(double)grid->nsubc_tot*grid->na_c, - nbl->nci_tot/(double)grid->nsubc_tot*grid->na_c/(0.5*4.0/3.0*M_PI*rl*rl*rl*grid->nsubc_tot*grid->na_c/(grid->size[XX]*grid->size[YY]*grid->size[ZZ]))); + nbl->na_ci, rl, nbl->nci_tot, nbl->nci_tot/static_cast(grid->nsubc_tot), + nbl->nci_tot/static_cast(grid->nsubc_tot)*grid->na_c, + nbl->nci_tot/static_cast(grid->nsubc_tot)*grid->na_c/(0.5*4.0/3.0*M_PI*rl*rl*rl*grid->nsubc_tot*grid->na_c/(grid->size[XX]*grid->size[YY]*grid->size[ZZ]))); sum_nsp = 0; sum_nsp2 = 0; @@ -1072,7 +1072,7 @@ static void print_nblist_statistics_supersub(FILE *fp, const nbnxn_pairlist_t *n { fprintf(fp, "nbl j-list #i-subcell %d %7d %4.1f\n", b, c[b], - 100.0*c[b]/(double)(nbl->ncj4*c_nbnxnGpuJgroupSize)); + 100.0*c[b]/static_cast(nbl->ncj4*c_nbnxnGpuJgroupSize)); } } } @@ -2168,12 +2168,12 @@ setExclusionsForGpuIentry(const nbnxn_search *nbs, static void nb_realloc_ci(nbnxn_pairlist_t *nbl, int n) { nbl->ci_nalloc = over_alloc_small(n); - nbnxn_realloc_void((void **)&nbl->ci, + nbnxn_realloc_void(reinterpret_cast(&nbl->ci), nbl->nci*sizeof(*nbl->ci), nbl->ci_nalloc*sizeof(*nbl->ci), nbl->alloc, nbl->free); - nbnxn_realloc_void((void **)&nbl->ciOuter, + nbnxn_realloc_void(reinterpret_cast(&nbl->ciOuter), nbl->nci*sizeof(*nbl->ciOuter), nbl->ci_nalloc*sizeof(*nbl->ciOuter), nbl->alloc, nbl->free); @@ -2183,7 +2183,7 @@ static void nb_realloc_ci(nbnxn_pairlist_t *nbl, int n) static void nb_realloc_sci(nbnxn_pairlist_t *nbl, int n) { nbl->sci_nalloc = over_alloc_small(n); - nbnxn_realloc_void((void **)&nbl->sci, + nbnxn_realloc_void(reinterpret_cast(&nbl->sci), nbl->nsci*sizeof(*nbl->sci), nbl->sci_nalloc*sizeof(*nbl->sci), nbl->alloc, nbl->free); @@ -2863,7 +2863,7 @@ static void combine_nblists(int nnbl, nbnxn_pairlist_t **nbl, if (ncj4 > nblc->cj4_nalloc) { nblc->cj4_nalloc = over_alloc_small(ncj4); - nbnxn_realloc_void((void **)&nblc->cj4, + nbnxn_realloc_void(reinterpret_cast(&nblc->cj4), nblc->ncj4*sizeof(*nblc->cj4), nblc->cj4_nalloc*sizeof(*nblc->cj4), nblc->alloc, nblc->free); @@ -2871,7 +2871,7 @@ static void combine_nblists(int nnbl, nbnxn_pairlist_t **nbl, if (nexcl > nblc->excl_nalloc) { nblc->excl_nalloc = over_alloc_small(nexcl); - nbnxn_realloc_void((void **)&nblc->excl, + nbnxn_realloc_void(reinterpret_cast(&nblc->excl), nblc->nexcl*sizeof(*nblc->excl), nblc->excl_nalloc*sizeof(*nblc->excl), nblc->alloc, nblc->free); @@ -3329,7 +3329,7 @@ static void nbnxn_make_pairlist_part(const nbnxn_search *nbs, if (debug) { fprintf(debug, "nbl nc_i %d col.av. %.1f ci_block %d\n", - gridi->nc, gridi->nc/(double)(gridi->numCells[XX]*gridi->numCells[YY]), ci_block); + gridi->nc, gridi->nc/static_cast(gridi->numCells[XX]*gridi->numCells[YY]), ci_block); } numDistanceChecks = 0; @@ -3865,10 +3865,10 @@ static void print_reduction_cost(const nbnxn_buffer_flags_t *flags, int nout) fprintf(debug, "nbnxn reduction: #flag %d #list %d elem %4.2f, keep %4.2f copy %4.2f red %4.2f\n", flags->nflag, nout, - nelem/(double)(flags->nflag), - nkeep/(double)(flags->nflag), - ncopy/(double)(flags->nflag), - nred/(double)(flags->nflag)); + nelem/static_cast(flags->nflag), + nkeep/static_cast(flags->nflag), + ncopy/static_cast(flags->nflag), + nred/static_cast(flags->nflag)); } /* Copies the list entries from src to dest when cjStart <= *cjGlobal < cjEnd. @@ -4074,7 +4074,7 @@ static void sort_sci(nbnxn_pairlist_t *nbl) if (work->sci_sort_nalloc != nbl->sci_nalloc) { work->sci_sort_nalloc = nbl->sci_nalloc; - nbnxn_realloc_void((void **)&work->sci_sort, + nbnxn_realloc_void(reinterpret_cast(&work->sci_sort), 0, work->sci_sort_nalloc*sizeof(*work->sci_sort), nbl->alloc, nbl->free); diff --git a/src/gromacs/mdlib/ns.cpp b/src/gromacs/mdlib/ns.cpp index 2e0085a958..46b51fd357 100644 --- a/src/gromacs/mdlib/ns.cpp +++ b/src/gromacs/mdlib/ns.cpp @@ -1923,7 +1923,7 @@ static int nsgrid_core(const t_commrec *cr, /* Calculate range of cells in Y direction that have the shift ty */ if (bTriclinicY) { - ygi = (int)(Ny + (YI - grid_offset[YY])*grid_y) - Ny; + ygi = static_cast(Ny + (YI - grid_offset[YY])*grid_y) - Ny; } else { @@ -1941,7 +1941,7 @@ static int nsgrid_core(const t_commrec *cr, /* Calculate range of cells in X direction that have the shift tx */ if (bTriclinicX) { - xgi = (int)(Nx + (XI - grid_offset[XX])*grid_x) - Nx; + xgi = static_cast(Nx + (XI - grid_offset[XX])*grid_x) - Nx; } else { @@ -2091,7 +2091,7 @@ void init_ns(FILE *fplog, const t_commrec *cr, const t_block *cgs = &molt.cgs; for (icg = 0; (icg < cgs->nr); icg++) { - nr_in_cg = std::max(nr_in_cg, (int)(cgs->index[icg+1]-cgs->index[icg])); + nr_in_cg = std::max(nr_in_cg, (cgs->index[icg+1]-cgs->index[icg])); } } diff --git a/src/gromacs/mdlib/nsgrid.cpp b/src/gromacs/mdlib/nsgrid.cpp index 6f734c362c..3c664b87a8 100644 --- a/src/gromacs/mdlib/nsgrid.cpp +++ b/src/gromacs/mdlib/nsgrid.cpp @@ -321,7 +321,7 @@ static void set_grid_sizes(matrix box, rvec izones_x0, rvec izones_x1, real rlis * we will use the normal grid ns that checks all cells * that are within cut-off distance of the i-particle. */ - grid->n[i] = (int)(size*inv_r_ideal + 0.5); + grid->n[i] = static_cast(size*inv_r_ideal + 0.5); if (grid->n[i] < 2) { grid->n[i] = 2; @@ -336,13 +336,13 @@ static void set_grid_sizes(matrix box, rvec izones_x0, rvec izones_x1, real rlis * We can then beforehand exclude certain ns grid cells * for non-home i-particles. */ - grid->ncpddc[i] = (int)(izones_size[i]*inv_r_ideal + 0.5); + grid->ncpddc[i] = static_cast(izones_size[i]*inv_r_ideal + 0.5); if (grid->ncpddc[i] < 2) { grid->ncpddc[i] = 2; } grid->cell_size[i] = izones_size[i]/grid->ncpddc[i]; - grid->n[i] = grid->ncpddc[i] + (int)(radd/grid->cell_size[i]) + 1; + grid->n[i] = grid->ncpddc[i] + static_cast(radd/grid->cell_size[i]) + 1; } if (debug) { diff --git a/src/gromacs/mdlib/qmmm.cpp b/src/gromacs/mdlib/qmmm.cpp index 1db60a41e6..e6c97ebbec 100644 --- a/src/gromacs/mdlib/qmmm.cpp +++ b/src/gromacs/mdlib/qmmm.cpp @@ -124,7 +124,7 @@ typedef struct { static int struct_comp(const void *a, const void *b) { - return (int)(((t_j_particle *)a)->j)-(int)(((t_j_particle *)b)->j); + return (((t_j_particle *)a)->j)-(((t_j_particle *)b)->j); } /* struct_comp */ @@ -692,13 +692,13 @@ void update_QMMMrec(const t_commrec *cr, qsort(qm_i_particles, QMMMlist->nri, - (size_t)sizeof(qm_i_particles[0]), + static_cast(sizeof(qm_i_particles[0])), struct_comp); /* The mm_j_particles argument to qsort is not allowed to be NULL */ if (mm_nr > 0) { qsort(mm_j_particles, mm_nr, - (size_t)sizeof(mm_j_particles[0]), + static_cast(sizeof(mm_j_particles[0])), struct_comp); } /* remove multiples in the QM shift array, since in init_QMMM() we diff --git a/src/gromacs/mdlib/repl_ex.cpp b/src/gromacs/mdlib/repl_ex.cpp index 53f8e09ec0..ce2021eb70 100644 --- a/src/gromacs/mdlib/repl_ex.cpp +++ b/src/gromacs/mdlib/repl_ex.cpp @@ -222,7 +222,7 @@ init_replica_exchange(FILE *fplog, bTemp = repl_quantity(ms, re, ereTEMP, re->temp); if (ir->efep != efepNO) { - bLambda = repl_quantity(ms, re, ereLAMBDA, (real)ir->fepvals->init_fep_state); + bLambda = repl_quantity(ms, re, ereLAMBDA, static_cast(ir->fepvals->init_fep_state)); } if (re->type == -1) /* nothing was assigned */ { @@ -337,7 +337,7 @@ init_replica_exchange(FILE *fplog, fprintf(fplog, "\nReplica exchange in lambda\n"); for (i = 0; i < re->nrepl; i++) { - fprintf(fplog, " %3d", (int)re->q[re->type][re->ind[i]]); + fprintf(fplog, " %3d", static_cast(re->q[re->type][re->ind[i]])); } fprintf(fplog, "\n"); break; @@ -350,7 +350,7 @@ init_replica_exchange(FILE *fplog, fprintf(fplog, "\n"); for (i = 0; i < re->nrepl; i++) { - fprintf(fplog, " %5d", (int)re->q[ereLAMBDA][re->ind[i]]); + fprintf(fplog, " %5d", static_cast(re->q[ereLAMBDA][re->ind[i]])); } fprintf(fplog, "\n"); break; @@ -869,7 +869,7 @@ test_for_replica_exchange(FILE *fplog, } for (i = 0; i < re->nrepl; i++) { - re->de[i][re->repl] = (enerd->enerpart_lambda[(int)re->q[ereLAMBDA][i]+1]-enerd->enerpart_lambda[0]); + re->de[i][re->repl] = (enerd->enerpart_lambda[static_cast(re->q[ereLAMBDA][i])+1]-enerd->enerpart_lambda[0]); } } @@ -1333,7 +1333,7 @@ void print_replica_exchange_statistics(FILE *fplog, struct gmx_repl_ex *re) } else { - re->prob[i] = ((real)re->nexchange[i])/re->nattempt[i%2]; + re->prob[i] = (static_cast(re->nexchange[i]))/re->nattempt[i%2]; } } print_ind(fplog, "", re->nrepl, re->ind, nullptr); diff --git a/src/gromacs/mdlib/rf_util.cpp b/src/gromacs/mdlib/rf_util.cpp index 705a6bcbb5..94b72e6aa0 100644 --- a/src/gromacs/mdlib/rf_util.cpp +++ b/src/gromacs/mdlib/rf_util.cpp @@ -253,7 +253,7 @@ void calc_rffac(FILE *fplog, int eel, real eps_r, real eps_rf, real Rc, real Tem else { k1 = 1 + kappa*Rc; - k2 = eps_rf*gmx::square((real)(kappa*Rc)); + k2 = eps_rf*gmx::square(static_cast(kappa*Rc)); *krf = ((eps_rf - eps_r)*k1 + 0.5*k2)/((2*eps_rf + eps_r)*k1 + k2)/(Rc*Rc*Rc); } diff --git a/src/gromacs/mdlib/shake.cpp b/src/gromacs/mdlib/shake.cpp index 232b06f648..2f448ff4bc 100644 --- a/src/gromacs/mdlib/shake.cpp +++ b/src/gromacs/mdlib/shake.cpp @@ -225,7 +225,7 @@ make_shake_sblock_serial(shakedata *shaked, fprintf(debug, "Going to sort constraints\n"); } - qsort(sb, ncons, (size_t)sizeof(*sb), pcomp); + qsort(sb, ncons, sizeof(*sb), pcomp); if (debug) { @@ -266,7 +266,7 @@ make_shake_sblock_serial(shakedata *shaked, } for (j = 0; (j <= shaked->nblocks); j++) { - fprintf(stderr, "sblock[%3d]=%5d\n", j, (int)shaked->sblock[j]); + fprintf(stderr, "sblock[%3d]=%5d\n", j, shaked->sblock[j]); } gmx_fatal(FARGS, "DEATH HORROR: " "sblocks does not match idef->il[F_CONSTR]"); diff --git a/src/gromacs/mdlib/shellfc.cpp b/src/gromacs/mdlib/shellfc.cpp index ba88a2118b..c2c5eb4c0d 100644 --- a/src/gromacs/mdlib/shellfc.cpp +++ b/src/gromacs/mdlib/shellfc.cpp @@ -849,7 +849,7 @@ static real rms_force(const t_commrec *cr, gmx::ArrayRef force, buf[2] = *sf_dir; buf[3] = *Epot; gmx_sumd(4, buf, cr); - ntot = (int)(buf[1] + 0.5); + ntot = static_cast(buf[1] + 0.5); *sf_dir = buf[2]; *Epot = buf[3]; } diff --git a/src/gromacs/mdlib/sighandler.cpp b/src/gromacs/mdlib/sighandler.cpp index 914bbe98cf..a9427de077 100644 --- a/src/gromacs/mdlib/sighandler.cpp +++ b/src/gromacs/mdlib/sighandler.cpp @@ -155,7 +155,7 @@ void signal_handler_install(void) gmx_stop_cond_t gmx_get_stop_condition(void) { - return (gmx_stop_cond_t)stop_condition; + return static_cast(stop_condition); } void gmx_set_stop_condition(gmx_stop_cond_t recvd_stop_cond) diff --git a/src/gromacs/mdlib/sim_util.cpp b/src/gromacs/mdlib/sim_util.cpp index 9cfc324715..682d342794 100644 --- a/src/gromacs/mdlib/sim_util.cpp +++ b/src/gromacs/mdlib/sim_util.cpp @@ -155,7 +155,7 @@ void print_time(FILE *out, { if (dt >= 300) { - finish = (time_t) (seconds_since_epoch + dt); + finish = static_cast(seconds_since_epoch + dt); gmx_ctime_r(&finish, timebuf, STRLEN); sprintf(buf, "%s", timebuf); buf[strlen(buf)-1] = '\0'; @@ -163,7 +163,7 @@ void print_time(FILE *out, } else { - fprintf(out, ", remaining wall clock time: %5d s ", (int)dt); + fprintf(out, ", remaining wall clock time: %5d s ", static_cast(dt)); } } else @@ -197,7 +197,7 @@ void print_date_and_time(FILE *fplog, int nodeid, const char *title, { int i; char timebuf[STRLEN]; - time_t temp_time = (time_t) the_time; + time_t temp_time = static_cast(the_time); gmx_ctime_r(&temp_time, timebuf, STRLEN); for (i = 0; timebuf[i] >= ' '; i++) @@ -2415,13 +2415,13 @@ void calc_enervirdiff(FILE *fplog, int eDispCorr, t_forcerec *fr) * Table has a scale factor since we have scaled it down to compensate * for scaling-up c6/c12 with the derivative factors to save flops in analytical kernels. */ - fr->enershiftsix = (real)(-1.0/(rc3*rc3)) - 6.0*vdwtab[8*ri0]; - fr->enershifttwelve = (real)( 1.0/(rc9*rc3)) - 12.0*vdwtab[8*ri0 + 4]; + fr->enershiftsix = static_cast(-1.0/(rc3*rc3)) - 6.0*vdwtab[8*ri0]; + fr->enershifttwelve = static_cast( 1.0/(rc9*rc3)) - 12.0*vdwtab[8*ri0 + 4]; } else if (ic->vdw_modifier == eintmodPOTSHIFT) { - fr->enershiftsix = (real)(-1.0/(rc3*rc3)); - fr->enershifttwelve = (real)( 1.0/(rc9*rc3)); + fr->enershiftsix = static_cast(-1.0/(rc3*rc3)); + fr->enershifttwelve = static_cast( 1.0/(rc9*rc3)); } /* Add the constant part from 0 to rvdw_switch. diff --git a/src/gromacs/mdrun/md.cpp b/src/gromacs/mdrun/md.cpp index a96a616a79..f7ebf89795 100644 --- a/src/gromacs/mdrun/md.cpp +++ b/src/gromacs/mdrun/md.cpp @@ -1344,7 +1344,7 @@ void gmx::Integrator::do_md() elapsed_time = walltime_accounting_get_current_elapsed_time(walltime_accounting); /* Check whether everything is still allright */ - if (((int)gmx_get_stop_condition() > handled_stop_condition) + if ((static_cast(gmx_get_stop_condition()) > handled_stop_condition) #if GMX_THREAD_MPI && MASTER(cr) #endif @@ -1385,7 +1385,7 @@ void gmx::Integrator::do_md() "\n\nReceived the %s signal, stopping within %d steps\n\n", gmx_get_signal_name(), nsteps_stop); fflush(stderr); - handled_stop_condition = (int)gmx_get_stop_condition(); + handled_stop_condition = static_cast(gmx_get_stop_condition()); } else if (MASTER(cr) && (bNS || ir->nstlist <= 0) && (max_hours > 0 && elapsed_time > max_hours*60.0*60.0*0.99) && diff --git a/src/gromacs/mdrun/minimize.cpp b/src/gromacs/mdrun/minimize.cpp index 6ce3ec0e34..45c35a0c6b 100644 --- a/src/gromacs/mdrun/minimize.cpp +++ b/src/gromacs/mdrun/minimize.cpp @@ -312,7 +312,7 @@ static void get_f_norm_max(const t_commrec *cr, if (sum[2*i] > fmax2) { fmax2 = sum[2*i]; - a_max = (int)(sum[2*i+1] + 0.5); + a_max = static_cast(sum[2*i+1] + 0.5); } } sfree(sum); @@ -549,7 +549,7 @@ static void write_em_traj(FILE *fplog, const t_commrec *cr, } mdoutf_write_to_trajectory_files(fplog, cr, outf, mdof_flags, - top_global, step, (double)step, + top_global, step, static_cast(step), &state->s, state_global, observablesHistory, state->f); @@ -1139,7 +1139,7 @@ Integrator::do_cg() if (MASTER(cr)) { /* Copy stuff to the energy bin for easy printing etc. */ - upd_mdebin(mdebin, FALSE, FALSE, (double)step, + upd_mdebin(mdebin, FALSE, FALSE, static_cast(step), mdatoms->tmass, enerd, &s_min->s, inputrec->fepvals, inputrec->expandedvals, s_min->s.box, nullptr, nullptr, vir, pres, nullptr, mu_tot, constr); @@ -1561,7 +1561,7 @@ Integrator::do_cg() fflush(stderr); } /* Store the new (lower) energies */ - upd_mdebin(mdebin, FALSE, FALSE, (double)step, + upd_mdebin(mdebin, FALSE, FALSE, static_cast(step), mdatoms->tmass, enerd, &s_min->s, inputrec->fepvals, inputrec->expandedvals, s_min->s.box, nullptr, nullptr, vir, pres, nullptr, mu_tot, constr); @@ -1804,7 +1804,7 @@ Integrator::do_lbfgs() if (MASTER(cr)) { /* Copy stuff to the energy bin for easy printing etc. */ - upd_mdebin(mdebin, FALSE, FALSE, (double)step, + upd_mdebin(mdebin, FALSE, FALSE, static_cast(step), mdatoms->tmass, enerd, state_global, inputrec->fepvals, inputrec->expandedvals, state_global->box, nullptr, nullptr, vir, pres, nullptr, mu_tot, constr); @@ -1889,7 +1889,7 @@ Integrator::do_lbfgs() } mdoutf_write_to_trajectory_files(fplog, cr, outf, mdof_flags, - top_global, step, (real)step, &ems.s, state_global, observablesHistory, ems.f); + top_global, step, static_cast(step), &ems.s, state_global, observablesHistory, ems.f); /* Do the linesearching in the direction dx[point][0..(n-1)] */ @@ -2290,7 +2290,7 @@ Integrator::do_lbfgs() fflush(stderr); } /* Store the new (lower) energies */ - upd_mdebin(mdebin, FALSE, FALSE, (double)step, + upd_mdebin(mdebin, FALSE, FALSE, static_cast(step), mdatoms->tmass, enerd, state_global, inputrec->fepvals, inputrec->expandedvals, state_global->box, nullptr, nullptr, vir, pres, nullptr, mu_tot, constr); do_log = do_per_step(step, inputrec->nstlog); @@ -2506,7 +2506,7 @@ Integrator::do_steep() if ( (count == 0) || (s_try->epot < s_min->epot) ) { /* Store the new (lower) energies */ - upd_mdebin(mdebin, FALSE, FALSE, (double)count, + upd_mdebin(mdebin, FALSE, FALSE, static_cast(count), mdatoms->tmass, enerd, &s_try->s, inputrec->fepvals, inputrec->expandedvals, s_try->s.box, nullptr, nullptr, vir, pres, nullptr, mu_tot, constr); @@ -2729,8 +2729,8 @@ Integrator::do_nm() if (bIsMaster) { - fprintf(stderr, "starting normal mode calculation '%s'\n%d steps.\n\n", - *(top_global->name), (int)inputrec->nsteps); + fprintf(stderr, "starting normal mode calculation '%s'\n%" PRId64 " steps.\n\n", + *(top_global->name), inputrec->nsteps); } nnodes = cr->nnodes; diff --git a/src/gromacs/mdrun/runner.cpp b/src/gromacs/mdrun/runner.cpp index 2af4727008..495c89d21f 100644 --- a/src/gromacs/mdrun/runner.cpp +++ b/src/gromacs/mdrun/runner.cpp @@ -1398,7 +1398,7 @@ int Mdrunner::mdrunner() gmx_fedisableexcept(); } - rc = (int)gmx_get_stop_condition(); + rc = static_cast(gmx_get_stop_condition()); #if GMX_THREAD_MPI /* we need to join all threads. The sub-threads join when they diff --git a/src/gromacs/mdrun/tpi.cpp b/src/gromacs/mdrun/tpi.cpp index 15eec2be09..4414c8ef29 100644 --- a/src/gromacs/mdrun/tpi.cpp +++ b/src/gromacs/mdrun/tpi.cpp @@ -316,8 +316,8 @@ Integrator::do_tpi() fprintf(fplog, "\nWill insert %d atoms %s partial charges\n", a_tp1-a_tp0, bCharge ? "with" : "without"); - fprintf(fplog, "\nWill insert %d times in each frame of %s\n", - (int)nsteps, opt2fn("-rerun", nfile, fnm)); + fprintf(fplog, "\nWill insert %" PRId64 " times in each frame of %s\n", + nsteps, opt2fn("-rerun", nfile, fnm)); } if (!bCavity) @@ -679,7 +679,7 @@ Integrator::do_tpi() { if (debug) { - fprintf(debug, "\n time %.3f, step %d: non-finite energy %f, using exp(-bU)=0\n", t, (int)step, epot); + fprintf(debug, "\n time %.3f, step %d: non-finite energy %f, using exp(-bU)=0\n", t, static_cast(step), epot); } embU = 0; } @@ -734,9 +734,9 @@ Integrator::do_tpi() } else { - i = (int)((bU_logV_bin_limit - - (beta*epot - logV + refvolshift))*invbinw - + 0.5); + i = static_cast((bU_logV_bin_limit + - (beta*epot - logV + refvolshift))*invbinw + + 0.5); if (i < 0) { i = 0; @@ -751,13 +751,13 @@ Integrator::do_tpi() if (debug) { fprintf(debug, "TPI %7d %12.5e %12.5f %12.5f %12.5f\n", - (int)step, epot, x_tp[XX], x_tp[YY], x_tp[ZZ]); + static_cast(step), epot, x_tp[XX], x_tp[YY], x_tp[ZZ]); } if (dump_pdb && epot <= dump_ener) { - sprintf(str, "t%g_step%d.pdb", t, (int)step); - sprintf(str2, "t: %f step %d ener: %f", t, (int)step, epot); + sprintf(str, "t%g_step%d.pdb", t, static_cast(step)); + sprintf(str2, "t: %f step %d ener: %f", t, static_cast(step), epot); write_sto_conf_mtop(str, str2, top_global, as_rvec_array(state_global->x.data()), as_rvec_array(state_global->v.data()), inputrec->ePBC, state_global->box); } @@ -848,7 +848,7 @@ Integrator::do_tpi() bUlogV = -i/invbinw + bU_logV_bin_limit - refvolshift + log(V_all/frame); fprintf(fp_tpi, "%6.2f %10d %12.5e\n", bUlogV, - (int)(bin[i]+0.5), + static_cast(bin[i]+0.5), bin[i]*exp(-bUlogV)*V_all/VembU_all); } xvgrclose(fp_tpi); diff --git a/src/gromacs/mdtypes/inputrec.cpp b/src/gromacs/mdtypes/inputrec.cpp index d4930fab39..8ca68dfafa 100644 --- a/src/gromacs/mdtypes/inputrec.cpp +++ b/src/gromacs/mdtypes/inputrec.cpp @@ -159,7 +159,7 @@ int ir_optimal_nsttcouple(const t_inputrec *ir) } else { - n = (int)(tau_min/(ir->delta_t*nmin) + 0.001); + n = static_cast(tau_min/(ir->delta_t*nmin) + 0.001); if (n < 1) { n = 1; diff --git a/src/gromacs/pbcutil/mshift.cpp b/src/gromacs/pbcutil/mshift.cpp index 0ee0cd0479..d7905596b1 100644 --- a/src/gromacs/pbcutil/mshift.cpp +++ b/src/gromacs/pbcutil/mshift.cpp @@ -810,7 +810,7 @@ void mk_mshift(FILE *log, t_graph *g, int ePBC, g->negc = nnodes; srenew(g->egc, g->negc); } - memset(g->egc, 0, (size_t)(nnodes*sizeof(g->egc[0]))); + memset(g->egc, 0, static_cast(nnodes*sizeof(g->egc[0]))); nW = g->nbound; nG = 0; diff --git a/src/gromacs/pulling/pull_rotation.cpp b/src/gromacs/pulling/pull_rotation.cpp index 1febabd34b..d199752d90 100644 --- a/src/gromacs/pulling/pull_rotation.cpp +++ b/src/gromacs/pulling/pull_rotation.cpp @@ -1525,7 +1525,7 @@ static real opt_angle_analytic( } sfree(eigvec); - return (real) opt_angle; + return static_cast(opt_angle); } diff --git a/src/gromacs/selection/evaluate.cpp b/src/gromacs/selection/evaluate.cpp index 05a5d38537..79a1d1d020 100644 --- a/src/gromacs/selection/evaluate.cpp +++ b/src/gromacs/selection/evaluate.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2009,2010,2011,2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by + * Copyright (c) 2009,2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -354,7 +354,7 @@ _gmx_sel_print_evalfunc_name(FILE *fp, gmx::sel_evalfunc evalfunc) } else { - fprintf(fp, "%p", (void*)(evalfunc)); + fprintf(fp, "%p", reinterpret_cast(evalfunc)); } } diff --git a/src/gromacs/selection/mempool.cpp b/src/gromacs/selection/mempool.cpp index 20134991fb..aebe432598 100644 --- a/src/gromacs/selection/mempool.cpp +++ b/src/gromacs/selection/mempool.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2010,2011,2012,2014,2017, by the GROMACS development team, led by + * Copyright (c) 2010,2011,2012,2014,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -186,7 +186,7 @@ _gmx_sel_mempool_free(gmx_sel_mempool_t *mp, void *ptr) mp->currsize -= size; if (mp->buffer) { - mp->freeptr = (char *)ptr; + mp->freeptr = static_cast(ptr); mp->freesize += size; } else @@ -205,7 +205,7 @@ _gmx_sel_mempool_reserve(gmx_sel_mempool_t *mp, size_t size) { size = mp->maxsize; } - mp->buffer = (char *)malloc(size); + mp->buffer = static_cast(malloc(size)); if (!mp->buffer) { throw std::bad_alloc(); diff --git a/src/gromacs/selection/parsetree.cpp b/src/gromacs/selection/parsetree.cpp index 9ec2750989..e9f8b49960 100644 --- a/src/gromacs/selection/parsetree.cpp +++ b/src/gromacs/selection/parsetree.cpp @@ -1214,5 +1214,5 @@ bool _gmx_sel_parser_should_finish(yyscan_t scanner) { gmx_ana_selcollection_t *sc = _gmx_sel_lexer_selcollection(scanner); - return (int)sc->sel.size() == _gmx_sel_lexer_exp_selcount(scanner); + return static_cast(sc->sel.size()) == _gmx_sel_lexer_exp_selcount(scanner); } diff --git a/src/gromacs/selection/sm_compare.cpp b/src/gromacs/selection/sm_compare.cpp index 84263f84f0..7df2342792 100644 --- a/src/gromacs/selection/sm_compare.cpp +++ b/src/gromacs/selection/sm_compare.cpp @@ -230,7 +230,7 @@ comparison_type_str(e_comparison_t cmpt) void _gmx_selelem_print_compare_info(FILE *fp, void *data) { - t_methoddata_compare *d = (t_methoddata_compare *)data; + t_methoddata_compare *d = static_cast(data); fprintf(fp, " \""); /* Print the left value */ @@ -352,7 +352,7 @@ convert_int_real(int n, t_compare_value *val) snew(rv, n); for (i = 0; i < n; ++i) { - rv[i] = (real)val->i[i]; + rv[i] = static_cast(val->i[i]); } /* Free the previous value if one is present. */ sfree(val->r); @@ -419,7 +419,7 @@ convert_real_int(int n, t_compare_value *val, e_comparison_t cmpt, bool bRight) static void init_compare(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data) { - t_methoddata_compare *d = (t_methoddata_compare *)data; + t_methoddata_compare *d = static_cast(data); int n1, n2; /* Store the values */ @@ -486,7 +486,7 @@ init_compare(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t *p static void free_data_compare(void *data) { - t_methoddata_compare *d = (t_methoddata_compare *)data; + t_methoddata_compare *d = static_cast(data); sfree(d->cmpop); if (d->left.flags & CMP_ALLOCINT) @@ -518,7 +518,7 @@ free_data_compare(void *data) static void evaluate_compare_int(gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data) { - t_methoddata_compare *d = (t_methoddata_compare *)data; + t_methoddata_compare *d = static_cast(data); int i, i1, i2, ig; int a, b; bool bAccept; @@ -567,7 +567,7 @@ evaluate_compare_int(gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data) static void evaluate_compare_real(gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data) { - t_methoddata_compare *d = (t_methoddata_compare *)data; + t_methoddata_compare *d = static_cast(data); int i, i1, i2, ig; real a, b; bool bAccept; @@ -607,7 +607,7 @@ static void evaluate_compare(const gmx::SelMethodEvalContext & /*context*/, gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data) { - t_methoddata_compare *d = (t_methoddata_compare *)data; + t_methoddata_compare *d = static_cast(data); if (!((d->left.flags | d->right.flags) & CMP_REALVAL)) { diff --git a/src/gromacs/selection/sm_insolidangle.cpp b/src/gromacs/selection/sm_insolidangle.cpp index e6835adeed..3e3890a411 100644 --- a/src/gromacs/selection/sm_insolidangle.cpp +++ b/src/gromacs/selection/sm_insolidangle.cpp @@ -405,7 +405,7 @@ init_data_insolidangle(int /* npar */, gmx_ana_selparam_t *param) static void init_insolidangle(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t * /* param */, void *data) { - t_methoddata_insolidangle *surf = (t_methoddata_insolidangle *)data; + t_methoddata_insolidangle *surf = static_cast(data); int i, c; if (surf->angcut <= 0) @@ -444,7 +444,7 @@ init_insolidangle(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam static void free_data_insolidangle(void *data) { - t_methoddata_insolidangle *d = (t_methoddata_insolidangle *)data; + t_methoddata_insolidangle *d = static_cast(data); int i; if (d->tbin) @@ -463,7 +463,7 @@ free_data_insolidangle(void *data) static void init_frame_insolidangle(const gmx::SelMethodEvalContext &context, void *data) { - t_methoddata_insolidangle *d = (t_methoddata_insolidangle *)data; + t_methoddata_insolidangle *d = static_cast(data); rvec dx; int i; @@ -495,7 +495,7 @@ init_frame_insolidangle(const gmx::SelMethodEvalContext &context, void *data) static bool accept_insolidangle(rvec x, const t_pbc *pbc, void *data) { - t_methoddata_insolidangle *d = (t_methoddata_insolidangle *)data; + t_methoddata_insolidangle *d = static_cast(data); rvec dx; if (pbc) @@ -594,7 +594,7 @@ _gmx_selelem_estimate_coverfrac(const gmx::SelectionTreeElement &sel) if (sel.type == SEL_EXPRESSION && sel.u.expr.method->name == sm_insolidangle.name) { - t_methoddata_insolidangle *d = (t_methoddata_insolidangle *)sel.u.expr.mdata; + t_methoddata_insolidangle *d = static_cast(sel.u.expr.mdata); if (d->cfrac < 0) { d->cfrac = estimate_covered_fraction(d); diff --git a/src/gromacs/selection/sm_keywords.cpp b/src/gromacs/selection/sm_keywords.cpp index 3e020fb4bc..6609900c67 100644 --- a/src/gromacs/selection/sm_keywords.cpp +++ b/src/gromacs/selection/sm_keywords.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2009,2010,2011,2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by + * Copyright (c) 2009,2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -443,7 +443,7 @@ init_data_kwint(int /* npar */, gmx_ana_selparam_t * /* param */) static void init_kwint(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data) { - t_methoddata_kwint *d = (t_methoddata_kwint *)data; + t_methoddata_kwint *d = static_cast(data); d->v = param[0].val.u.i; d->n = param[1].val.nr; @@ -462,7 +462,7 @@ static void evaluate_keyword_int(const gmx::SelMethodEvalContext & /*context*/, gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data) { - t_methoddata_kwint *d = (t_methoddata_kwint *)data; + t_methoddata_kwint *d = static_cast(data); int n, i, j, jmin, jmax; int val; @@ -518,7 +518,7 @@ init_data_kwreal(int /* npar */, gmx_ana_selparam_t * /* param */) static void init_kwreal(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data) { - t_methoddata_kwreal *d = (t_methoddata_kwreal *)data; + t_methoddata_kwreal *d = static_cast(data); d->v = param[0].val.u.r; d->n = param[1].val.nr; @@ -537,7 +537,7 @@ static void evaluate_keyword_real(const gmx::SelMethodEvalContext & /*context*/, gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data) { - t_methoddata_kwreal *d = (t_methoddata_kwreal *)data; + t_methoddata_kwreal *d = static_cast(data); int n, i, j, jmin, jmax; real val; diff --git a/src/gromacs/selection/sm_merge.cpp b/src/gromacs/selection/sm_merge.cpp index 4066c5d931..26298901c1 100644 --- a/src/gromacs/selection/sm_merge.cpp +++ b/src/gromacs/selection/sm_merge.cpp @@ -200,7 +200,7 @@ init_data_merge(int npar, gmx_ana_selparam_t *param) static void init_merge(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t * /* param */, void *data) { - t_methoddata_merge *d = (t_methoddata_merge *)data; + t_methoddata_merge *d = static_cast(data); if (d->stride < 0) { @@ -227,7 +227,7 @@ init_merge(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t * /* static void init_output_common(const gmx_mtop_t *top, gmx_ana_selvalue_t *out, void *data) { - t_methoddata_merge *d = (t_methoddata_merge *)data; + t_methoddata_merge *d = static_cast(data); GMX_UNUSED_VALUE(top); if (d->p1.m.type != d->p2.m.type) @@ -253,7 +253,7 @@ init_output_common(const gmx_mtop_t *top, gmx_ana_selvalue_t *out, void *data) static void init_output_merge(const gmx_mtop_t *top, gmx_ana_selvalue_t *out, void *data) { - t_methoddata_merge *d = (t_methoddata_merge *)data; + t_methoddata_merge *d = static_cast(data); int i, j; init_output_common(top, out, data); @@ -275,7 +275,7 @@ init_output_merge(const gmx_mtop_t *top, gmx_ana_selvalue_t *out, void *data) static void init_output_plus(const gmx_mtop_t *top, gmx_ana_selvalue_t *out, void *data) { - t_methoddata_merge *d = (t_methoddata_merge *)data; + t_methoddata_merge *d = static_cast(data); int i; init_output_common(top, out, data); @@ -297,7 +297,7 @@ init_output_plus(const gmx_mtop_t *top, gmx_ana_selvalue_t *out, void *data) static void free_data_merge(void *data) { - t_methoddata_merge *d = (t_methoddata_merge *)data; + t_methoddata_merge *d = static_cast(data); delete d; } @@ -305,7 +305,7 @@ static void evaluate_merge(const gmx::SelMethodEvalContext & /*context*/, gmx_ana_pos_t * /* p */, gmx_ana_selvalue_t *out, void *data) { - t_methoddata_merge *d = (t_methoddata_merge *)data; + t_methoddata_merge *d = static_cast(data); int i, j; int refid; @@ -335,7 +335,7 @@ static void evaluate_plus(const gmx::SelMethodEvalContext & /*context*/, gmx_ana_pos_t * /* p */, gmx_ana_selvalue_t *out, void *data) { - t_methoddata_merge *d = (t_methoddata_merge *)data; + t_methoddata_merge *d = static_cast(data); int i; int refid; diff --git a/src/gromacs/selection/sm_permute.cpp b/src/gromacs/selection/sm_permute.cpp index e4b8b51510..0b942e5445 100644 --- a/src/gromacs/selection/sm_permute.cpp +++ b/src/gromacs/selection/sm_permute.cpp @@ -171,7 +171,7 @@ init_data_permute(int /* npar */, gmx_ana_selparam_t *param) static void init_permute(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data) { - t_methoddata_permute *d = (t_methoddata_permute *)data; + t_methoddata_permute *d = static_cast(data); int i; d->n = param[1].val.nr; @@ -204,7 +204,7 @@ init_permute(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t *p static void init_output_permute(const gmx_mtop_t * /* top */, gmx_ana_selvalue_t *out, void *data) { - t_methoddata_permute *d = (t_methoddata_permute *)data; + t_methoddata_permute *d = static_cast(data); int i, j, b; out->u.p->m.type = d->p.m.type; @@ -229,7 +229,7 @@ init_output_permute(const gmx_mtop_t * /* top */, gmx_ana_selvalue_t *out, void static void free_data_permute(void *data) { - t_methoddata_permute *d = (t_methoddata_permute *)data; + t_methoddata_permute *d = static_cast(data); sfree(d->rperm); delete d; @@ -239,7 +239,7 @@ static void evaluate_permute(const gmx::SelMethodEvalContext & /*context*/, gmx_ana_pos_t * /*p*/, gmx_ana_selvalue_t *out, void *data) { - t_methoddata_permute *d = (t_methoddata_permute *)data; + t_methoddata_permute *d = static_cast(data); int i, j, b; int refid; diff --git a/src/gromacs/selection/sm_position.cpp b/src/gromacs/selection/sm_position.cpp index ad0b2c1a8d..e78d79b542 100644 --- a/src/gromacs/selection/sm_position.cpp +++ b/src/gromacs/selection/sm_position.cpp @@ -224,7 +224,7 @@ init_data_pos(int npar, gmx_ana_selparam_t *param) static void set_poscoll_pos(gmx::PositionCalculationCollection *pcc, void *data) { - ((t_methoddata_pos *)data)->pcc = pcc; + (static_cast(data))->pcc = pcc; } bool @@ -276,7 +276,7 @@ static void set_pos_method_flags(gmx_ana_selmethod_t *method, void _gmx_selelem_set_kwpos_type(gmx::SelectionTreeElement *sel, const char *type) { - t_methoddata_pos *d = (t_methoddata_pos *)sel->u.expr.mdata; + t_methoddata_pos *d = static_cast(sel->u.expr.mdata); if (sel->type != SEL_EXPRESSION || !sel->u.expr.method || sel->u.expr.method->name != sm_keyword_pos.name) @@ -302,7 +302,7 @@ _gmx_selelem_set_kwpos_type(gmx::SelectionTreeElement *sel, const char *type) void _gmx_selelem_set_kwpos_flags(gmx::SelectionTreeElement *sel, int flags) { - t_methoddata_pos *d = (t_methoddata_pos *)sel->u.expr.mdata; + t_methoddata_pos *d = static_cast(sel->u.expr.mdata); if (sel->type != SEL_EXPRESSION || !sel->u.expr.method || sel->u.expr.method->name != sm_keyword_pos.name) @@ -321,7 +321,7 @@ _gmx_selelem_set_kwpos_flags(gmx::SelectionTreeElement *sel, int flags) static void init_kwpos(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data) { - t_methoddata_pos *d = (t_methoddata_pos *)data; + t_methoddata_pos *d = static_cast(data); if (!(param[0].flags & SPAR_DYNAMIC)) { @@ -338,7 +338,7 @@ init_kwpos(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t *par static void init_cog(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data) { - t_methoddata_pos *d = (t_methoddata_pos *)data; + t_methoddata_pos *d = static_cast(data); d->flags = (param[0].flags & SPAR_DYNAMIC) ? POS_DYNAMIC : 0; d->pc = d->pcc->createCalculation(d->bPBC ? POS_ALL_PBC : POS_ALL, d->flags); @@ -348,7 +348,7 @@ init_cog(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t *param static void init_com(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data) { - t_methoddata_pos *d = (t_methoddata_pos *)data; + t_methoddata_pos *d = static_cast(data); d->flags = (param[0].flags & SPAR_DYNAMIC) ? POS_DYNAMIC : 0; d->flags |= POS_MASS; @@ -359,7 +359,7 @@ init_com(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t *param static void init_output_pos(const gmx_mtop_t * /* top */, gmx_ana_selvalue_t *out, void *data) { - t_methoddata_pos *d = (t_methoddata_pos *)data; + t_methoddata_pos *d = static_cast(data); gmx_ana_poscalc_init_pos(d->pc, out->u.p); } @@ -373,7 +373,7 @@ init_output_pos(const gmx_mtop_t * /* top */, gmx_ana_selvalue_t *out, void *dat static void free_data_pos(void *data) { - t_methoddata_pos *d = (t_methoddata_pos *)data; + t_methoddata_pos *d = static_cast(data); sfree(d->type); gmx_ana_poscalc_free(d->pc); @@ -391,7 +391,7 @@ static void evaluate_pos(const gmx::SelMethodEvalContext &context, gmx_ana_index_t * /* g */, gmx_ana_selvalue_t *out, void *data) { - t_methoddata_pos *d = (t_methoddata_pos *)data; + t_methoddata_pos *d = static_cast(data); gmx_ana_poscalc_update(d->pc, out->u.p, &d->g, context.fr, context.pbc); } diff --git a/src/gromacs/selection/sm_same.cpp b/src/gromacs/selection/sm_same.cpp index 58210bd736..b98a8e0bfb 100644 --- a/src/gromacs/selection/sm_same.cpp +++ b/src/gromacs/selection/sm_same.cpp @@ -284,7 +284,7 @@ _gmx_selelem_custom_init_same(gmx_ana_selmethod_t **me static void init_same(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data) { - t_methoddata_same *d = (t_methoddata_same *)data; + t_methoddata_same *d = static_cast(data); d->val.ptr = param[0].val.u.ptr; d->as.ptr = param[1].val.u.ptr; @@ -306,7 +306,7 @@ init_same(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t *para static void free_data_same(void *data) { - t_methoddata_same *d = (t_methoddata_same *)data; + t_methoddata_same *d = static_cast(data); sfree(d->as_s_sorted); sfree(d); @@ -332,7 +332,7 @@ cmp_int(const void *a, const void *b) static void init_frame_same_int(const gmx::SelMethodEvalContext & /*context*/, void *data) { - t_methoddata_same *d = (t_methoddata_same *)data; + t_methoddata_same *d = static_cast(data); int i, j; /* Collapse adjacent values, and check whether the array is sorted. */ @@ -385,7 +385,7 @@ static void evaluate_same_int(const gmx::SelMethodEvalContext & /*context*/, gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data) { - t_methoddata_same *d = (t_methoddata_same *)data; + t_methoddata_same *d = static_cast(data); int i, j; out->u.g->isize = 0; @@ -454,13 +454,13 @@ evaluate_same_int(const gmx::SelMethodEvalContext & /*context*/, static int cmp_str(const void *a, const void *b) { - return strcmp(*(char **)a, *(char **)b); + return strcmp(*static_cast(a), *static_cast(b)); } static void init_frame_same_str(const gmx::SelMethodEvalContext & /*context*/, void *data) { - t_methoddata_same *d = (t_methoddata_same *)data; + t_methoddata_same *d = static_cast(data); int i, j; /* Collapse adjacent values. @@ -508,7 +508,7 @@ static void evaluate_same_str(const gmx::SelMethodEvalContext & /*context*/, gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data) { - t_methoddata_same *d = (t_methoddata_same *)data; + t_methoddata_same *d = static_cast(data); int j; out->u.g->isize = 0; diff --git a/src/gromacs/statistics/statistics.cpp b/src/gromacs/statistics/statistics.cpp index ac62fce847..9bf546a5d4 100644 --- a/src/gromacs/statistics/statistics.cpp +++ b/src/gromacs/statistics/statistics.cpp @@ -65,12 +65,12 @@ gmx_stats_t gmx_stats_init() snew(stats, 1); - return (gmx_stats_t) stats; + return static_cast(stats); } int gmx_stats_get_npoints(gmx_stats_t gstats, int *N) { - gmx_stats *stats = (gmx_stats *) gstats; + gmx_stats *stats = static_cast(gstats); *N = stats->np; @@ -79,7 +79,7 @@ int gmx_stats_get_npoints(gmx_stats_t gstats, int *N) void gmx_stats_free(gmx_stats_t gstats) { - gmx_stats *stats = (gmx_stats *) gstats; + gmx_stats *stats = static_cast(gstats); sfree(stats->x); sfree(stats->y); diff --git a/src/gromacs/swap/swapcoords.cpp b/src/gromacs/swap/swapcoords.cpp index bb1d941749..5f436e41d3 100644 --- a/src/gromacs/swap/swapcoords.cpp +++ b/src/gromacs/swap/swapcoords.cpp @@ -419,7 +419,7 @@ static gmx_bool compartment_contains_atom( x += l; } - *distance_from_b = (real)fabs(x - bulkOffset*0.5*width); + *distance_from_b = static_cast(fabs(x - bulkOffset*0.5*width)); /* Return TRUE if we now are in area "????" */ return (x >= w1) && (x < w2); diff --git a/src/gromacs/tables/forcetable.cpp b/src/gromacs/tables/forcetable.cpp index 0d4d73ca65..d62720a7a1 100644 --- a/src/gromacs/tables/forcetable.cpp +++ b/src/gromacs/tables/forcetable.cpp @@ -708,7 +708,7 @@ static void read_tables(FILE *fp, const char *fn, if (ns > 0) { ssd /= ns; - sprintf(buf, "For the %d non-zero entries for table %d in %s the forces deviate on average %lld%% from minus the numerical derivative of the potential\n", ns, k, libfn, (long long int)(100*ssd+0.5)); + sprintf(buf, "For the %d non-zero entries for table %d in %s the forces deviate on average %lld%% from minus the numerical derivative of the potential\n", ns, k, libfn, static_cast(100*ssd+0.5)); if (debug) { fprintf(debug, "%s", buf); @@ -1369,7 +1369,7 @@ t_forcetable *make_tables(FILE *out, gmx_fatal(FARGS, "Tables in file %s not long enough for cut-off:\n" "\tshould be at least %f nm\n", fn, rtab); } - table->n = (int)(rtab*td[0].tabscale + 0.5); + table->n = static_cast(rtab*td[0].tabscale + 0.5); } table->scale = td[0].tabscale; nx0 = td[0].nx0; diff --git a/src/gromacs/timing/wallcycle.cpp b/src/gromacs/timing/wallcycle.cpp index 765cfdda10..2bcd5d3442 100644 --- a/src/gromacs/timing/wallcycle.cpp +++ b/src/gromacs/timing/wallcycle.cpp @@ -1054,7 +1054,7 @@ void wallcycle_print(FILE *fplog, const gmx::MDLogger &mdlog, int nnodes, int np GMX_LOG(mdlog.warning).asParagraph().appendTextFormatted( "NOTE: %d %% of the run time was spent in pair search,\n" " you might want to increase nstlist (this has no effect on accuracy)\n", - (int)(100*cyc_sum[ewcNS]/tot+0.5)); + static_cast(100*cyc_sum[ewcNS]/tot+0.5)); } else { @@ -1062,8 +1062,8 @@ void wallcycle_print(FILE *fplog, const gmx::MDLogger &mdlog, int nnodes, int np "NOTE: %d %% of the run time was spent in domain decomposition,\n" " %d %% of the run time was spent in pair search,\n" " you might want to increase nstlist (this has no effect on accuracy)\n", - (int)(100*cyc_sum[ewcDOMDEC]/tot+0.5), - (int)(100*cyc_sum[ewcNS]/tot+0.5)); + static_cast(100*cyc_sum[ewcDOMDEC]/tot+0.5), + static_cast(100*cyc_sum[ewcNS]/tot+0.5)); } } @@ -1072,7 +1072,7 @@ void wallcycle_print(FILE *fplog, const gmx::MDLogger &mdlog, int nnodes, int np GMX_LOG(mdlog.warning).asParagraph().appendTextFormatted( "NOTE: %d %% of the run time was spent communicating energies,\n" " you might want to use the -gcom option of mdrun\n", - (int)(100*cyc_sum[ewcMoveE]/tot+0.5)); + static_cast(100*cyc_sum[ewcMoveE]/tot+0.5)); } } diff --git a/src/gromacs/tools/convert_tpr.cpp b/src/gromacs/tools/convert_tpr.cpp index 62c0bbaa7b..d4fca39d74 100644 --- a/src/gromacs/tools/convert_tpr.cpp +++ b/src/gromacs/tools/convert_tpr.cpp @@ -404,7 +404,7 @@ int gmx_convert_tpr(int argc, char *argv[]) /* Determine total number of steps remaining */ if (bExtend) { - ir->nsteps = ir->nsteps - (run_step - ir->init_step) + (int64_t)(extend_t/ir->delta_t + 0.5); + ir->nsteps = ir->nsteps - (run_step - ir->init_step) + static_cast(extend_t/ir->delta_t + 0.5); printf("Extending remaining runtime of by %g ps (now %s steps)\n", extend_t, gmx_step_str(ir->nsteps, buf)); } @@ -414,7 +414,7 @@ int gmx_convert_tpr(int argc, char *argv[]) gmx_step_str(ir->nsteps, buf), gmx_step_str(run_step, buf2), run_t, until_t); - ir->nsteps = (int64_t)((until_t - run_t)/ir->delta_t + 0.5); + ir->nsteps = static_cast((until_t - run_t)/ir->delta_t + 0.5); printf("Extending remaining runtime until %g ps (now %s steps)\n", until_t, gmx_step_str(ir->nsteps, buf)); } diff --git a/src/gromacs/topology/atomprop.cpp b/src/gromacs/topology/atomprop.cpp index d4bffefe6e..e9af594dd4 100644 --- a/src/gromacs/topology/atomprop.cpp +++ b/src/gromacs/topology/atomprop.cpp @@ -138,8 +138,8 @@ static int get_prop_index(aprop_t *ap, gmx_residuetype_t *restype, } } - *bExact = ((malen == (long int)strlen(atomnm)) && - ((mrlen == (long int)strlen(resnm)) || + *bExact = ((malen == static_cast(strlen(atomnm))) && + ((mrlen == static_cast(strlen(resnm))) || ((mrlen == WILDPROT) && bProtWild) || ((mrlen == WILDCARD) && !bProtein && !bProtWild))); @@ -213,7 +213,7 @@ static void add_prop(aprop_t *ap, gmx_residuetype_t *restype, static void read_prop(gmx_atomprop_t aps, int eprop, double factor) { - gmx_atomprop *ap2 = (gmx_atomprop*) aps; + gmx_atomprop *ap2 = static_cast(aps); FILE *fp; char line[STRLEN], resnm[32], atomnm[32]; double pp; @@ -247,7 +247,7 @@ static void read_prop(gmx_atomprop_t aps, int eprop, double factor) static void set_prop(gmx_atomprop_t aps, int eprop) { - gmx_atomprop *ap2 = (gmx_atomprop*) aps; + gmx_atomprop *ap2 = static_cast(aps); const char *fns[epropNR] = { "atommass.dat", "vdwradii.dat", "dgsolv.dat", "electroneg.dat", "elements.dat" }; double fac[epropNR] = { 1.0, 1.0, 418.4, 1.0, 1.0 }; double def[epropNR] = { 12.011, 0.14, 0.0, 2.2, -1 }; @@ -289,7 +289,7 @@ gmx_atomprop_t gmx_atomprop_init(void) aps->bWarned = FALSE; aps->bWarnVDW = FALSE; - return (gmx_atomprop_t)aps; + return static_cast(aps); } static void destroy_prop(aprop_t *ap) @@ -314,7 +314,7 @@ static void destroy_prop(aprop_t *ap) void gmx_atomprop_destroy(gmx_atomprop_t aps) { - gmx_atomprop *ap = (gmx_atomprop*) aps; + gmx_atomprop *ap = static_cast(aps); int p; if (aps == nullptr) @@ -349,7 +349,7 @@ gmx_bool gmx_atomprop_query(gmx_atomprop_t aps, int eprop, const char *resnm, const char *atomnm, real *value) { - gmx_atomprop *ap = (gmx_atomprop*) aps; + gmx_atomprop *ap = static_cast(aps); int j; #define MAXQ 32 char atomname[MAXQ], resname[MAXQ]; @@ -403,7 +403,7 @@ gmx_bool gmx_atomprop_query(gmx_atomprop_t aps, char *gmx_atomprop_element(gmx_atomprop_t aps, int atomnumber) { - gmx_atomprop *ap = (gmx_atomprop*) aps; + gmx_atomprop *ap = static_cast(aps); int i; set_prop(aps, epropElement); @@ -419,7 +419,7 @@ char *gmx_atomprop_element(gmx_atomprop_t aps, int atomnumber) int gmx_atomprop_atomnumber(gmx_atomprop_t aps, const char *elem) { - gmx_atomprop *ap = (gmx_atomprop*) aps; + gmx_atomprop *ap = static_cast(aps); int i; set_prop(aps, epropElement); diff --git a/src/gromacs/topology/index.cpp b/src/gromacs/topology/index.cpp index c5bc7beb35..49a4b708d6 100644 --- a/src/gromacs/topology/index.cpp +++ b/src/gromacs/topology/index.cpp @@ -423,7 +423,7 @@ static void analyse_prot(const char ** restype, const t_atoms *atoms, } } /* find matching or complement atoms */ - for (i = 0; (i < (int)num_index_groups); i++) + for (i = 0; (i < num_index_groups); i++) { nra = 0; for (n = 0; (n < atoms->nr); n++) @@ -470,7 +470,7 @@ static void analyse_prot(const char ** restype, const t_atoms *atoms, if (bASK) { - for (i = 0; (i < (int)num_index_groups); i++) + for (i = 0; (i < num_index_groups); i++) { printf("Split %12s into %5d residues (y/n) ? ", constructing_data[i].group_name, npres); if (gmx_ask_yesno(bASK)) @@ -829,7 +829,7 @@ static void minstring(char *str) { int i; - for (i = 0; (i < (int)strlen(str)); i++) + for (i = 0; (i < static_cast(strlen(str))); i++) { if (str[i] == '-') { diff --git a/src/gromacs/topology/mtop_util.cpp b/src/gromacs/topology/mtop_util.cpp index 0d777546b2..2dfd10f4c1 100644 --- a/src/gromacs/topology/mtop_util.cpp +++ b/src/gromacs/topology/mtop_util.cpp @@ -610,30 +610,30 @@ static void atomcat(t_atoms *dest, const t_atoms *src, int copies, /* residue information */ for (l = dest->nres, j = 0; (j < copies); j++, l += src->nres) { - memcpy((char *) &(dest->resinfo[l]), (char *) &(src->resinfo[0]), - (size_t)(src->nres*sizeof(src->resinfo[0]))); + memcpy(reinterpret_cast(&(dest->resinfo[l])), reinterpret_cast(&(src->resinfo[0])), + static_cast(src->nres*sizeof(src->resinfo[0]))); } for (l = destnr, j = 0; (j < copies); j++, l += srcnr) { - memcpy((char *) &(dest->atom[l]), (char *) &(src->atom[0]), - (size_t)(srcnr*sizeof(src->atom[0]))); - memcpy((char *) &(dest->atomname[l]), (char *) &(src->atomname[0]), - (size_t)(srcnr*sizeof(src->atomname[0]))); + memcpy(reinterpret_cast(&(dest->atom[l])), reinterpret_cast(&(src->atom[0])), + static_cast(srcnr*sizeof(src->atom[0]))); + memcpy(reinterpret_cast(&(dest->atomname[l])), reinterpret_cast(&(src->atomname[0])), + static_cast(srcnr*sizeof(src->atomname[0]))); if (dest->haveType) { - memcpy((char *) &(dest->atomtype[l]), (char *) &(src->atomtype[0]), - (size_t)(srcnr*sizeof(src->atomtype[0]))); + memcpy(reinterpret_cast(&(dest->atomtype[l])), reinterpret_cast(&(src->atomtype[0])), + static_cast(srcnr*sizeof(src->atomtype[0]))); if (dest->haveBState) { - memcpy((char *) &(dest->atomtypeB[l]), (char *) &(src->atomtypeB[0]), - (size_t)(srcnr*sizeof(src->atomtypeB[0]))); + memcpy(reinterpret_cast(&(dest->atomtypeB[l])), reinterpret_cast(&(src->atomtypeB[0])), + static_cast(srcnr*sizeof(src->atomtypeB[0]))); } } if (dest->havePdbInfo) { - memcpy((char *) &(dest->pdbinfo[l]), (char *) &(src->pdbinfo[0]), - (size_t)(srcnr*sizeof(src->pdbinfo[0]))); + memcpy(reinterpret_cast(&(dest->pdbinfo[l])), reinterpret_cast(&(src->pdbinfo[0])), + static_cast(srcnr*sizeof(src->pdbinfo[0]))); } } diff --git a/src/gromacs/topology/symtab.cpp b/src/gromacs/topology/symtab.cpp index 0798390d26..eb5693e301 100644 --- a/src/gromacs/topology/symtab.cpp +++ b/src/gromacs/topology/symtab.cpp @@ -64,7 +64,7 @@ static char *trim_string(const char *s, char *out, int maxlen) { int len, i; - if (strlen(s) > (size_t)(maxlen-1)) + if (strlen(s) > static_cast(maxlen-1)) { gmx_fatal(FARGS, "String '%s' (%zu) is longer than buffer (%d).\n", s, strlen(s), maxlen-1); diff --git a/src/gromacs/topology/topology.cpp b/src/gromacs/topology/topology.cpp index 5ab83dad4f..f033222567 100644 --- a/src/gromacs/topology/topology.cpp +++ b/src/gromacs/topology/topology.cpp @@ -549,7 +549,7 @@ static void cmp_idef(FILE *fp, const t_idef *id1, const t_idef *id2, real ftol, { sprintf(buf1, "idef->functype[%d]", i); sprintf(buf2, "idef->iparam[%d]", i); - cmp_int(fp, buf1, i, (int)id1->functype[i], (int)id2->functype[i]); + cmp_int(fp, buf1, i, static_cast(id1->functype[i]), static_cast(id2->functype[i])); cmp_iparm(fp, buf2, id1->functype[i], id1->iparams[i], id2->iparams[i], ftol, abstol); } diff --git a/src/gromacs/trajectoryanalysis/modules/surfacearea.cpp b/src/gromacs/trajectoryanalysis/modules/surfacearea.cpp index 3f7a4249fa..0400f388ad 100644 --- a/src/gromacs/trajectoryanalysis/modules/surfacearea.cpp +++ b/src/gromacs/trajectoryanalysis/modules/surfacearea.cpp @@ -117,7 +117,7 @@ static void divarc(real x1, real y1, real z1, GMX_ASSERT(d2 >= 0.5, "Vector 2 too short"); phi = safe_asin(dd/std::sqrt(d1*d2)); - phi = phi*((real)div1)/((real)div2); + phi = phi*(static_cast(div1))/(static_cast(div2)); sphi = sin(phi); cphi = cos(phi); s = (x1*xd+y1*yd+z1*zd)/dd; @@ -140,8 +140,8 @@ static std::vector ico_dot_arc(int densit) xjk, yjk, zjk, xkj, ykj, zkj; /* calculate tessalation level */ - a = std::sqrt((((real) densit)-2.)/10.); - const int tess = (int) ceil(a); + a = std::sqrt(((static_cast(densit))-2.)/10.); + const int tess = static_cast(ceil(a)); const int ndot = 10*tess*tess+2; GMX_RELEASE_ASSERT(ndot >= densit, "Inconsistent surface dot formula"); @@ -263,8 +263,8 @@ static std::vector ico_dot_dod(int densit) xjk, yjk, zjk, xkj, ykj, zkj; /* calculate tesselation level */ - a = std::sqrt((((real) densit)-2.)/30.); - tess = std::max((int) ceil(a), 1); + a = std::sqrt(((static_cast(densit))-2.)/30.); + tess = std::max(static_cast(ceil(a)), 1); const int ndot = 30*tess*tess+2; GMX_RELEASE_ASSERT(ndot >= densit, "Inconsistent surface dot formula"); @@ -487,21 +487,21 @@ static std::vector make_unsp(int densit, int cubus) ico_cube = std::max(i-1, 0); } ico_cube_cb = ico_cube*ico_cube*ico_cube; - const real del_cube = 2./((real)ico_cube); + const real del_cube = 2./(static_cast(ico_cube)); snew(work, ndot); for (l = 0; l < ndot; l++) { - i = std::max((int) floor((1.+xus[3*l])/del_cube), 0); + i = std::max(static_cast(floor((1.+xus[3*l])/del_cube)), 0); if (i >= ico_cube) { i = ico_cube-1; } - j = std::max((int) floor((1.+xus[1+3*l])/del_cube), 0); + j = std::max(static_cast(floor((1.+xus[1+3*l])/del_cube)), 0); if (j >= ico_cube) { j = ico_cube-1; } - k = std::max((int) floor((1.+xus[2+3*l])/del_cube), 0); + k = std::max(static_cast(floor((1.+xus[2+3*l])/del_cube)), 0); if (k >= ico_cube) { k = ico_cube-1; @@ -561,7 +561,7 @@ nsc_dclm_pbc(const rvec *coords, const ArrayRef &radius, int nat, int index[], AnalysisNeighborhood *nb, const t_pbc *pbc) { - const real dotarea = FOURPI/(real) n_dot; + const real dotarea = FOURPI/static_cast(n_dot); if (debug) { diff --git a/src/gromacs/utility/binaryinformation.cpp b/src/gromacs/utility/binaryinformation.cpp index cb138cf36b..27be14f4b8 100644 --- a/src/gromacs/utility/binaryinformation.cpp +++ b/src/gromacs/utility/binaryinformation.cpp @@ -239,7 +239,7 @@ void gmx_print_version_info(gmx::TextWriter *writer) #else writer->writeLine("Precision: single"); #endif - writer->writeLine(formatString("Memory model: %u bit", (unsigned)(8*sizeof(void *)))); + writer->writeLine(formatString("Memory model: %u bit", static_cast(8*sizeof(void *)))); #if GMX_THREAD_MPI writer->writeLine("MPI library: thread_mpi"); diff --git a/src/gromacs/utility/cstringutil.cpp b/src/gromacs/utility/cstringutil.cpp index c403994a3b..f92a4b8c15 100644 --- a/src/gromacs/utility/cstringutil.cpp +++ b/src/gromacs/utility/cstringutil.cpp @@ -127,7 +127,7 @@ void upstring (char *str) { int i; - for (i = 0; (i < (int)strlen(str)); i++) + for (i = 0; (i < static_cast(strlen(str))); i++) { str[i] = toupper(str[i]); } @@ -211,8 +211,8 @@ int gmx_strncasecmp_min(const char *str1, const char *str2, int n) char ch1, ch2; char *stri1, *stri2; - stri1 = (char *)str1; - stri2 = (char *)str2; + stri1 = const_cast(str1); + stri2 = const_cast(str2); do { do diff --git a/src/gromacs/utility/qsort_threadsafe.cpp b/src/gromacs/utility/qsort_threadsafe.cpp index e5a6404b38..5339b1be20 100644 --- a/src/gromacs/utility/qsort_threadsafe.cpp +++ b/src/gromacs/utility/qsort_threadsafe.cpp @@ -54,8 +54,8 @@ qsort_swapfunc(void * a, if (swaptype <= 1) { - ia = (int *)a; - ib = (int *)b; + ia = static_cast(a); + ib = static_cast(b); for (; n > 0; ia += 1, ib += 1, n -= sizeof(int)) { itmp = *ia; @@ -65,8 +65,8 @@ qsort_swapfunc(void * a, } else { - ca = (char *)a; - cb = (char *)b; + ca = static_cast(a); + cb = static_cast(b); for (; n > 0; ca += 1, cb += 1, n -= 1) { ctmp = *ca; @@ -136,9 +136,9 @@ gmx_qsort(void * base, return; } - cbase = (char *)base; + cbase = static_cast(base); - swaptype = (size_t)(cbase - (char *)nullptr) % sizeof(int) || size % sizeof(int) ? 2 : size == sizeof(int) ? 0 : 1; + swaptype = static_cast(cbase - (char *)nullptr) % sizeof(int) || size % sizeof(int) ? 2 : size == sizeof(int) ? 0 : 1; if (nmemb < 7) { @@ -164,12 +164,12 @@ gmx_qsort(void * base, { /* Big arrays, pseudomedian of 9 */ s = (nmemb/8)*size; - pl = (char *)qsort_med3((void *)pl, (void *)((size_t)pl+s), (void *)((size_t)pl+2*s), compar); - pm = (char *)qsort_med3((void *)((size_t)pm-s), (void *)pm, (void *)((size_t)pm+s), compar); - pn = (char *)qsort_med3((void *)((size_t)pn-2*s), (void *)((size_t)pn-s), (void *)pn, compar); + pl = static_cast(qsort_med3((void *)pl, (void *)((size_t)pl+s), (void *)((size_t)pl+2*s), compar)); + pm = static_cast(qsort_med3((void *)((size_t)pm-s), (void *)pm, (void *)((size_t)pm+s), compar)); + pn = static_cast(qsort_med3((void *)((size_t)pn-2*s), (void *)((size_t)pn-s), (void *)pn, compar)); } /* Mid-size, med of 3 */ - pm = (char *)qsort_med3((void *)pl, (void *)pm, (void *)pn, compar); + pm = static_cast(qsort_med3((void *)pl, (void *)pm, (void *)pn, compar)); } /* pv points to partition value */ @@ -180,8 +180,8 @@ gmx_qsort(void * base, } else { - v = *(int *)pm; - pv = (char*)(void*)&v; + v = *reinterpret_cast(pm); + pv = static_cast((void*)&v); } pa = pb = cbase; diff --git a/src/gromacs/utility/smalloc.cpp b/src/gromacs/utility/smalloc.cpp index 97f3d0a6c1..7c68694125 100644 --- a/src/gromacs/utility/smalloc.cpp +++ b/src/gromacs/utility/smalloc.cpp @@ -79,7 +79,7 @@ void *save_malloc(const char *name, const char *file, int line, size_t size) gmx_fatal(errno, __FILE__, __LINE__, "Not enough memory. Failed to malloc %" PRId64 " bytes for %s\n" "(called from file %s, line %d)", - (int64_t)size, name, file, line); + static_cast(size), name, file, line); } (void) memset(p, 0, size); } @@ -120,13 +120,13 @@ void *save_calloc(const char *name, const char *file, int line, } memset(p, 0, (size_t) (nelem * elsize)); #else - if ((p = calloc((size_t)nelem, (size_t)elsize)) == nullptr) + if ((p = calloc(nelem, elsize)) == nullptr) { gmx_fatal(errno, __FILE__, __LINE__, "Not enough memory. Failed to calloc %" PRId64 " elements of size %" PRId64 " for %s\n(called from file %s, line %d)", - (int64_t)nelem, (int64_t)elsize, name, file, line); + static_cast(nelem), static_cast(elsize), name, file, line); } #endif } @@ -156,18 +156,18 @@ void *save_realloc(const char *name, const char *file, int line, void *ptr, #endif if (ptr == nullptr) { - p = malloc((size_t)size); + p = malloc(size); } else { - p = realloc(ptr, (size_t)size); + p = realloc(ptr, size); } if (p == nullptr) { gmx_fatal(errno, __FILE__, __LINE__, "Not enough memory. Failed to realloc %" PRId64 " bytes for %s, %s=%x\n" "(called from file %s, line %d)", - (int64_t)size, name, name, ptr, file, line); + static_cast(size), name, name, ptr, file, line); } } return p; @@ -237,7 +237,7 @@ void *save_calloc_aligned(const char *name, const char *file, int line, void *aligned = save_malloc_aligned(name, file, line, nelem, elsize, alignment); if (aligned != nullptr) { - memset(aligned, 0, (size_t)(nelem * elsize)); + memset(aligned, 0, static_cast(nelem * elsize)); } return aligned; } -- 2.22.0