diff --git a/ChangeLog b/ChangeLog
index 90012f86777a88f0611550441f9b7d2053c80b78..12e7ed38011097e6b5b731a6eaae0cc020d7b21d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2024-07-23  Uwe Schulzweida
+
+	* Make code c++20 compliant
+
 2024-06-28  Uwe Schulzweida
 
 	* Added check for NetCDF4.8 function ncaux_h5filterspec_parselist()
diff --git a/src/async_worker.c b/src/async_worker.c
index 277a3fe702611f853509c2f7179aa3d19ce15fb3..e04222b3afedf517418f08dc526597db11973a9e 100644
--- a/src/async_worker.c
+++ b/src/async_worker.c
@@ -145,9 +145,9 @@ AsyncWorker_init(AsyncManager **jobManager, int threadCount)
   if (*jobManager) return CDI_NOERR;
 
 #ifdef HAVE_LIBPTHREAD
-  AsyncManager *jobManager_ = *jobManager = Malloc(sizeof(AsyncManager));
+  AsyncManager *jobManager_ = *jobManager = (AsyncManager *) Malloc(sizeof(AsyncManager));
   jobManager_->workerCount = threadCount;
-  jobManager_->communicators = Malloc((size_t) threadCount * sizeof(AsyncJob));
+  jobManager_->communicators = (AsyncJob *) Malloc((size_t) threadCount * sizeof(AsyncJob));
 
   for (int i = 0; i < threadCount; i++) startWorker(jobManager_->communicators + i);
   jobManager_->idleWorkerCount = threadCount;
diff --git a/src/binary.h b/src/binary.h
index de6a5e479c7ffebe001c210f8fab5a54ef405016..d06e0e0157cd84f4f11cfd2cd6f0c4434f43f40e 100644
--- a/src/binary.h
+++ b/src/binary.h
@@ -9,13 +9,8 @@
 #include <inttypes.h>
 
 #ifndef HOST_ENDIANNESS
-#ifdef __cplusplus
-static const uint32_t HOST_ENDIANNESS_temp[1] = { UINT32_C(0x00030201) };
-#define HOST_ENDIANNESS (((const unsigned char *) HOST_ENDIANNESS_temp)[0])
-#else
 #define HOST_ENDIANNESS (((const unsigned char *) &(const uint32_t[1]){ UINT32_C(0x00030201) })[0])
 #endif
-#endif
 
 uint32_t get_uint32(unsigned char *x);
 uint64_t get_uint64(unsigned char *x);
diff --git a/src/cdf_filter.c b/src/cdf_filter.c
index dec8a5b0531b8dc1807dbf29fc4c4efa067e388f..615208ca3c0e2bce59972f73e112abb3b27a3978 100644
--- a/src/cdf_filter.c
+++ b/src/cdf_filter.c
@@ -2,6 +2,7 @@
 #include "config.h"
 #endif
 
+#include "cdi.h"
 #include "cdf_filter.h"
 #include "error.h"
 
diff --git a/src/cdf_read.c b/src/cdf_read.c
index b5b4bc3002b4decffe6b7d2052fd085a6d153d8d..a5d1f836a2e7c16b850c211e410bec1e82083ffd 100644
--- a/src/cdf_read.c
+++ b/src/cdf_read.c
@@ -825,9 +825,9 @@ job_args_init(stream_t *streamptr, long tsID, long recID, int memtype, void *dat
     .streamptr = streamptr,
     .varID = varID,
     .levelID = levelID,
+    .memtype = memtype,
     .recID = recID,
     .tsID = tsID,
-    .memtype = memtype,
     .data = data,
     .gridsize = gridsize,
     .numMissVals = 0,
diff --git a/src/cdi_key.c b/src/cdi_key.c
index ca7e19eb641a6d3c8e7497aab5b4f921ccd59982..e5c00dc940f93e8d4787300d09139a28c98f4648 100644
--- a/src/cdi_key.c
+++ b/src/cdi_key.c
@@ -495,7 +495,7 @@ cdiDefVarKeyBytes(cdi_keys_t *keysp, int key, const unsigned char *bytes, int le
         }
       if (keyp->length == 0)
         {
-          keyp->v.s = Malloc(length_);
+          keyp->v.s = (unsigned char *) Malloc(length_);
           keyp->length = length;
         }
 
diff --git a/src/cdi_query.c b/src/cdi_query.c
index d74012f2e4801c4a8f41eb947c07ddacecfdb9c9..9f7c3bbca6ad87509ae8244b30f22d38d0cd534c 100644
--- a/src/cdi_query.c
+++ b/src/cdi_query.c
@@ -54,7 +54,7 @@ cdiQueryInit(CdiQuery *query)
 CdiQuery *
 cdiQueryCreate(void)
 {
-  CdiQuery *query = Malloc(sizeof(CdiQuery));
+  CdiQuery *query = (CdiQuery *) Malloc(sizeof(CdiQuery));
   cdiQueryInit(query);
   return query;
 }
@@ -138,8 +138,8 @@ cdiQuerySetCellidx(CdiQuery *query, int numEntries, size_t *cellidx)
     {
       query->numEntries += numEntries;
       query->numCellidx = numEntries;
-      query->cellidxFound = Calloc((size_t) numEntries, sizeof(bool));
-      query->cellidx = Malloc((size_t) numEntries * sizeof(size_t));
+      query->cellidxFound = (bool *) Calloc((size_t) numEntries, sizeof(bool));
+      query->cellidx = (size_t *) Malloc((size_t) numEntries * sizeof(size_t));
       for (int i = 0; i < numEntries; ++i) query->cellidx[i] = cellidx[i];
     }
 }
@@ -151,8 +151,8 @@ cdiQuerySetLevidx(CdiQuery *query, int numEntries, int *levidx)
     {
       query->numEntries += numEntries;
       query->numLevidx = numEntries;
-      query->levidxFound = Calloc((size_t) numEntries, sizeof(bool));
-      query->levidx = Malloc((size_t) numEntries * sizeof(int));
+      query->levidxFound = (bool *) Calloc((size_t) numEntries, sizeof(bool));
+      query->levidx = (int *) Malloc((size_t) numEntries * sizeof(int));
       for (int i = 0; i < numEntries; ++i) query->levidx[i] = levidx[i];
     }
 }
@@ -164,8 +164,8 @@ cdiQuerySetStepidx(CdiQuery *query, int numEntries, int *stepidx)
     {
       query->numEntries += numEntries;
       query->numStepidx = numEntries;
-      query->stepidxFound = Calloc((size_t) numEntries, sizeof(bool));
-      query->stepidx = Malloc((size_t) numEntries * sizeof(int));
+      query->stepidxFound = (bool *) Calloc((size_t) numEntries, sizeof(bool));
+      query->stepidx = (int *) Malloc((size_t) numEntries * sizeof(int));
       for (int i = 0; i < numEntries; ++i) query->stepidx[i] = stepidx[i];
     }
 }
diff --git a/src/cgribexlib.c b/src/cgribexlib.c
index 5a0b0655aa0c3d78d7a7710f2dedb983fc85e19b..a19337c13e190a9af685feea5cd8497e3b124761 100644
--- a/src/cgribexlib.c
+++ b/src/cgribexlib.c
@@ -1219,13 +1219,8 @@ xlc_r -g -O3 -qhot -q64 -qarch=auto -qtune=auto -qreport -DTEST_ENCODE encode_ar
 #define GRIBPACK unsigned char
 
 #ifndef HOST_ENDIANNESS
-#ifdef __cplusplus
-static const uint32_t HOST_ENDIANNESS_temp[1] = { UINT32_C(0x00030201) };
-#define HOST_ENDIANNESS (((const unsigned char *) HOST_ENDIANNESS_temp)[0])
-#else
 #define HOST_ENDIANNESS (((const unsigned char *) &(const uint32_t[1]){ UINT32_C(0x00030201) })[0])
 #endif
-#endif
 
 #define IS_BIGENDIAN() (HOST_ENDIANNESS == 0)
 #define Error(x, y)
diff --git a/src/grb_read.c b/src/grb_read.c
index 324365b35375a80844de08ac7b2b2f7d50506be2..628f43b8b317cc16be5163e45aa1210c5b6e96d3 100644
--- a/src/grb_read.c
+++ b/src/grb_read.c
@@ -173,6 +173,7 @@ grb_read_raw_data(stream_t *streamptr, int tsID, int recID, int memType, void *g
     .outZip = &streamptr->tsteps[tsID].records[recID].zip,
     .filetype = streamptr->filetype,
     .memType = memType,
+    .datatype = vlistInqVarDatatype(vlistID, varID),
     .unreduced = streamptr->unreduced,
     .cgribexp = cgribexp,
     .gribbuffer = gribbuffer,
@@ -181,7 +182,6 @@ grb_read_raw_data(stream_t *streamptr, int tsID, int recID, int memType, void *g
     .gridsize = gridsize,
     .numMissVals = 0,
     .missval = vlistInqVarMissval(vlistID, varID),
-    .datatype = vlistInqVarDatatype(vlistID, varID),
   };
 }
 
@@ -280,7 +280,7 @@ grb_read_next_record(stream_t *streamptr, int recID, int memType, void *data, si
       // if this is the first call, init and start worker threads
       if (!jobs)
         {
-          jobs = Malloc((size_t) workerCount * sizeof(*jobs));
+          jobs = (JobDescriptorGRB *) Malloc((size_t) workerCount * sizeof(*jobs));
           streamptr->jobs = jobs;
           for (int i = 0; i < workerCount; i++) jobs[i].args.recID = -1;
           for (int i = 0; i < workerCount; i++) jobs[i].args.tsID = -1;
diff --git a/src/grb_write.c b/src/grb_write.c
index 4978514834512a1c6a1588c841da00208e24f6b1..f9c9ec8d02b344815bcca5ad83fb80f10e5dbfe0 100644
--- a/src/grb_write.c
+++ b/src/grb_write.c
@@ -58,7 +58,7 @@ grb_encode(int filetype, int memType, int varID, int levelID, int vlistID, int g
         {
           // printf("gribapi write: convert float to double\n");
           const float *dataf = (const float *) data;
-          double *datad = Malloc((size_t) datasize * sizeof(double));
+          double *datad = (double *) Malloc((size_t) datasize * sizeof(double));
           for (size_t i = 0; i < (size_t) datasize; ++i) datad[i] = (double) dataf[i];
           datap = (const void *) datad;
         }
diff --git a/src/gribapi_utilities.c b/src/gribapi_utilities.c
index 8f950c492c993175da7833073439e5334bf985e8..7d45150803ce435a1b184442906c4a5011589fcc 100644
--- a/src/gribapi_utilities.c
+++ b/src/gribapi_utilities.c
@@ -275,7 +275,7 @@ makeDateString(struct tm *me)
   {
     size = 4 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 4 + 1
   };
-  char *result = Malloc(size);
+  char *result = (char *) Malloc(size);
   assert(me->tm_year + 1900 < 10000 && me->tm_year + 1900 > -1000 && me->tm_mon >= 0 && me->tm_mon < 12 && me->tm_mday >= 1
          && me->tm_mday <= 31 && me->tm_hour >= 0 && me->tm_hour <= 24 && me->tm_min >= 0 && me->tm_min < 60 && me->tm_sec >= 0
          && me->tm_sec <= 60);
@@ -425,6 +425,7 @@ gribapiTimeIsFC(grib_handle *gh)
 
 struct cdiGribAPI_ts_str_map_elem cdiGribAPI_ts_str_map[] = {
   // clang-format off
+  [0]             = {  0, "" },
   [TSTEP_INSTANT] = {  0, "instant" },
   [TSTEP_AVG]     = {  8, "avg" },
   [TSTEP_ACCUM]   = {  8, "accum" },
@@ -435,8 +436,7 @@ struct cdiGribAPI_ts_str_map_elem cdiGribAPI_ts_str_map[] = {
   [TSTEP_SD]      = {  8, "sd" },
   [TSTEP_COV]     = {  8, "cov" },
   [TSTEP_RATIO]   = {  8, "ratio" },
-  [TSTEP_SUM]     = {  8, "sum" },
-                    {  0, "" }
+  [TSTEP_SUM]     = {  8, "sum" }
   // clang-format on
 };
 
@@ -454,7 +454,7 @@ gribapiGetTsteptype(grib_handle *gh)
       int status = grib_get_string(gh, "stepType", stepType, &len);
       if (status == 0 && len > 1 && len < 256)
         {
-          for (int i = TSTEP_INSTANT; cdiGribAPI_ts_str_map[i].sname[0]; ++i)
+          for (int i = TSTEP_INSTANT; i <= TSTEP_SUM; ++i)
             if (strncmp(cdiGribAPI_ts_str_map[i].sname, stepType, len) == 0)
               {
                 tsteptype = i;
diff --git a/src/grid.c b/src/grid.c
index 21563206c2d977c46d98aaf46d11416d1f4254db..9e2897e9209f7d10922920ebd88fa2ae56c1ed0b 100644
--- a/src/grid.c
+++ b/src/grid.c
@@ -86,7 +86,7 @@ cdiInqAttConvertedToFloat(int gridID, int atttype, const char *attname, int attl
   if (atttype == CDI_DATATYPE_INT32)
     {
       int attint = 0;
-      int *pattint = attlen > 1 ? Malloc((size_t) attlen * sizeof(int)) : &attint;
+      int *pattint = attlen > 1 ? (int *) Malloc((size_t) attlen * sizeof(int)) : &attint;
       cdiInqAttInt(gridID, CDI_GLOBAL, attname, attlen, pattint);
       for (int i = 0; i < attlen; ++i) attflt[i] = (double) pattint[i];
       if (attlen > 1) Free(pattint);
@@ -358,7 +358,7 @@ gridGenXvals(size_t xsize, double xfirst, double xlast, double xinc, double *res
 static void
 calc_gaussgrid(double *restrict yvals, size_t ysize, double yfirst, double ylast)
 {
-  double *restrict yw = Malloc(ysize * sizeof(double));
+  double *restrict yw = (double *) Malloc(ysize * sizeof(double));
   gaussianLatitudes(ysize, yvals, yw);
   Free(yw);
   for (size_t i = 0; i < ysize; i++) yvals[i] = asin(yvals[i]) / M_PI * 180.0;
@@ -390,7 +390,7 @@ gridGenYvalsGaussian(size_t ysize, double yfirst, double ylast, double *restrict
         ny -= ny % 2;
         if (ny > 0 && (size_t) ny > ysize && ny < 4096)
           {
-            double *ytmp = Malloc((size_t) ny * sizeof(double));
+            double *ytmp = (double *) Malloc((size_t) ny * sizeof(double));
             calc_gaussgrid(ytmp, (size_t) ny, yfirst, ylast);
 
             size_t nstart = (size_t) ny - ysize;
@@ -2649,7 +2649,7 @@ grid_complete(grid_t *grid)
         if (grid->x.flag == 2)
           {
             assert(gridtype != GRID_UNSTRUCTURED && gridtype != GRID_CURVILINEAR);
-            double *xvals = Malloc(grid->x.size * sizeof(double));
+            double *xvals = (double *) Malloc(grid->x.size * sizeof(double));
             gridGenXvals(grid->x.size, grid->x.first, grid->x.last, grid->x.inc, xvals);
             grid->x.vals = xvals;
             // gridDefXinc(gridID, grid->x.inc);
@@ -4559,7 +4559,7 @@ gridUnpackArrays(grid_t *gridP, int memberMask, char *unpackBuffer, int unpackBu
   if (memberMask & gridHasReducedPointsFlag)
     {
       xassert(gridP->reducedPointsSize);
-      gridP->reducedPoints = Malloc((size_t) gridP->reducedPointsSize * sizeof(int));
+      gridP->reducedPoints = (int *) Malloc((size_t) gridP->reducedPointsSize * sizeof(int));
       serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos, gridP->reducedPoints, gridP->reducedPointsSize,
                       CDI_DATATYPE_INT, context);
       serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos, &d, 1, CDI_DATATYPE_UINT32, context);
@@ -4571,7 +4571,7 @@ gridUnpackArrays(grid_t *gridP, int memberMask, char *unpackBuffer, int unpackBu
     {
       size_t size = isIrregular ? gridP->size : gridP->x.size;
       xassert(size <= INT_MAX);
-      gridP->x.vals = Malloc(size * sizeof(double));
+      gridP->x.vals = (double *) Malloc(size * sizeof(double));
       serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos, gridP->x.vals, (int) size, CDI_DATATYPE_FLT64, context);
       serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos, &d, 1, CDI_DATATYPE_UINT32, context);
       xassert(cdiCheckSum(CDI_DATATYPE_FLT, (int) size, gridP->x.vals) == d);
@@ -4581,7 +4581,7 @@ gridUnpackArrays(grid_t *gridP, int memberMask, char *unpackBuffer, int unpackBu
     {
       size_t size = isIrregular ? gridP->size : gridP->y.size;
       xassert(size > 0 && size <= INT_MAX);
-      gridP->y.vals = Malloc(size * sizeof(double));
+      gridP->y.vals = (double *) Malloc(size * sizeof(double));
       serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos, gridP->y.vals, (int) size, CDI_DATATYPE_FLT64, context);
       serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos, &d, 1, CDI_DATATYPE_UINT32, context);
       xassert(cdiCheckSum(CDI_DATATYPE_FLT, (int) size, gridP->y.vals) == d);
@@ -4591,7 +4591,7 @@ gridUnpackArrays(grid_t *gridP, int memberMask, char *unpackBuffer, int unpackBu
     {
       size_t size = gridP->size;
       xassert(size > 0 && size <= INT_MAX);
-      gridP->area = Malloc(size * sizeof(double));
+      gridP->area = (double *) Malloc(size * sizeof(double));
       serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos, gridP->area, (int) size, CDI_DATATYPE_FLT64, context);
       serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos, &d, 1, CDI_DATATYPE_UINT32, context);
       xassert(cdiCheckSum(CDI_DATATYPE_FLT, (int) size, gridP->area) == d);
@@ -4602,7 +4602,7 @@ gridUnpackArrays(grid_t *gridP, int memberMask, char *unpackBuffer, int unpackBu
       size_t size = (size_t) gridP->nvertex * (isIrregular ? gridP->size : gridP->x.size);
       xassert(size > 0 && size <= INT_MAX);
 
-      gridP->x.bounds = Malloc(size * sizeof(double));
+      gridP->x.bounds = (double *) Malloc(size * sizeof(double));
       serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos, gridP->x.bounds, (int) size, CDI_DATATYPE_FLT64, context);
       serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos, &d, 1, CDI_DATATYPE_UINT32, context);
       xassert(cdiCheckSum(CDI_DATATYPE_FLT, (int) size, gridP->x.bounds) == d);
@@ -4612,7 +4612,7 @@ gridUnpackArrays(grid_t *gridP, int memberMask, char *unpackBuffer, int unpackBu
     {
       size_t size = (size_t) gridP->nvertex * (isIrregular ? gridP->size : gridP->y.size);
       xassert(size && size <= INT_MAX);
-      gridP->y.bounds = Malloc(size * sizeof(double));
+      gridP->y.bounds = (double *) Malloc(size * sizeof(double));
       serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos, gridP->y.bounds, (int) size, CDI_DATATYPE_FLT64, context);
       serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos, &d, 1, CDI_DATATYPE_UINT32, context);
       xassert(cdiCheckSum(CDI_DATATYPE_FLT, (int) size, gridP->y.bounds) == d);
@@ -4622,7 +4622,7 @@ gridUnpackArrays(grid_t *gridP, int memberMask, char *unpackBuffer, int unpackBu
     {
       size_t size = gridP->size;
       xassert(size && size <= INT_MAX);
-      gridP->mask = Malloc(size * sizeof(mask_t));
+      gridP->mask = (mask_t *) Malloc(size * sizeof(mask_t));
       serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos, gridP->mask, (int) size, CDI_DATATYPE_UCHAR, context);
       serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos, &d, 1, CDI_DATATYPE_UINT32, context);
       xassert(cdiCheckSum(CDI_DATATYPE_UCHAR, (int) size, gridP->mask) == d);
@@ -4632,7 +4632,7 @@ gridUnpackArrays(grid_t *gridP, int memberMask, char *unpackBuffer, int unpackBu
     {
       size_t size = gridP->size;
       xassert(size && size <= INT_MAX);
-      gridP->mask_gme = Malloc(size * sizeof(mask_t));
+      gridP->mask_gme = (mask_t *) Malloc(size * sizeof(mask_t));
       serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos, gridP->mask_gme, (int) size, CDI_DATATYPE_UCHAR, context);
       serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos, &d, 1, CDI_DATATYPE_UINT32, context);
       xassert(cdiCheckSum(CDI_DATATYPE_UCHAR, (int) size, gridP->mask_gme) == d);
diff --git a/src/iterator_fallback.c b/src/iterator_fallback.c
index 0c2b5b711deeb6b8bdce1f3f50db8bb6870a8318..eb561f4d11716a67f6e37fa39993e2f2a4962361 100644
--- a/src/iterator_fallback.c
+++ b/src/iterator_fallback.c
@@ -355,14 +355,9 @@ int
 cdiFallbackIterator_inqTile(CdiIterator *super, int *outTileIndex, int *outTileAttribute)
 {
   CdiFallbackIterator *me = (CdiFallbackIterator *) (void *) super;
-#ifndef __cplusplus
-  if (!outTileIndex) outTileIndex = &(int){ 0 };
-  if (!outTileAttribute) outTileAttribute = &(int){ 0 };
-#else
   int dummy = 0;
   if (!outTileIndex) outTileIndex = &dummy;
   if (!outTileAttribute) outTileAttribute = &dummy;
-#endif
 
   int error = CDI_NOERR;
   if (me->subtypeId == CDI_UNDEFID)  // must not call subtypeInqAttribute() with an invalid subtype ID, because it would abort the
@@ -383,14 +378,9 @@ int
 cdiFallbackIterator_inqTileCount(CdiIterator *super, int *outTileCount, int *outTileAttributeCount)
 {
   CdiFallbackIterator *me = (CdiFallbackIterator *) (void *) super;
-#ifndef __cplusplus
-  if (!outTileCount) outTileCount = &(int){ 0 };
-  if (!outTileAttributeCount) outTileAttributeCount = &(int){ 0 };
-#else
   int temp = 0;
   if (!outTileCount) outTileCount = &temp;
   if (!outTileAttributeCount) outTileAttributeCount = &temp;
-#endif
 
   int error = CDI_NOERR;
   if (me->subtypeId == CDI_UNDEFID)  // must not call subtypeInqAttribute() with an invalid subtype ID, because it would abort the
diff --git a/src/stream_cdf_i.c b/src/stream_cdf_i.c
index bd847f56d99cefad1e6a7f07ea6bb69d829176bb..fa0aa6706fb2e8b2da62736a0d655d4c5ca603c6 100644
--- a/src/stream_cdf_i.c
+++ b/src/stream_cdf_i.c
@@ -210,7 +210,7 @@ set_base_time(const char *timeUnitsStr, taxis_t *taxis)
       len--;
     }
   char tmp[32], *tu = tmp;
-  if (len + 1 > sizeof(tmp)) tu = Malloc(len + 1);
+  if (len + 1 > sizeof(tmp)) tu = (char *) Malloc(len + 1);
 
   for (size_t i = 0; i < len; i++) tu[i] = (char) tolower((int) timeUnitsStr[i]);
   tu[len] = 0;
@@ -397,7 +397,7 @@ cdfGetAttInt(int fileID, int ncvarid, const char *attname, size_t attlen, int *a
   if (xtypeIsFloat(atttype) || xtypeIsInt(atttype))
     {
       bool needAlloc = (nc_attlen > attlen);
-      int *pintatt = needAlloc ? Malloc(nc_attlen * sizeof(int)) : attint;
+      int *pintatt = needAlloc ? (int *) Malloc(nc_attlen * sizeof(int)) : attint;
       cdf_get_att_int(fileID, ncvarid, attname, pintatt);
       if (needAlloc)
         {
@@ -419,7 +419,7 @@ cdfGetAttInt64(int fileID, int ncvarid, const char *attname, size_t attlen, int6
 
   if (xtypeIsFloat(atttype) || xtypeIsInt(atttype) || xtypeIsInt64(atttype))
     {
-      long long *plongatt = Malloc(nc_attlen * sizeof(long long));
+      long long *plongatt = (long long *) Malloc(nc_attlen * sizeof(long long));
       cdf_get_att_longlong(fileID, ncvarid, attname, plongatt);
       for (size_t i = 0; i < attlen; ++i) attint[i] = plongatt[i];
       Free(plongatt);
@@ -439,7 +439,7 @@ cdfGetAttDouble(int fileID, int ncvarid, char *attname, size_t attlen, double *a
   if (xtypeIsFloat(atttype) || xtypeIsInt(atttype))
     {
       bool needAlloc = (nc_attlen > attlen);
-      double *pdoubleatt = needAlloc ? Malloc(nc_attlen * sizeof(double)) : attdouble;
+      double *pdoubleatt = needAlloc ? (double *) Malloc(nc_attlen * sizeof(double)) : attdouble;
       cdf_get_att_double(fileID, ncvarid, attname, pdoubleatt);
       if (needAlloc)
         {
@@ -865,7 +865,7 @@ cdf_set_cdi_attr(int ncid, int ncvarid, int attnum, int cdiID, int varID, bool r
   if (xtypeIsInt(atttype))
     {
       int attint = 0;
-      int *pattint = (attlen > 1) ? Malloc(attlen * sizeof(int)) : &attint;
+      int *pattint = (attlen > 1) ? (int *) Malloc(attlen * sizeof(int)) : &attint;
       cdfGetAttInt(ncid, ncvarid, attname, attlen, pattint);
       // clang-format off
       int datatype = (atttype == NC_SHORT)  ? CDI_DATATYPE_INT16 :
@@ -883,7 +883,7 @@ cdf_set_cdi_attr(int ncid, int ncvarid, int attnum, int cdiID, int varID, bool r
   else if (xtypeIsInt64(atttype))
     {
       int64_t attint64 = 0;
-      int64_t *pattint64 = (attlen > 1) ? Malloc(attlen * sizeof(int64_t)) : &attint64;
+      int64_t *pattint64 = (attlen > 1) ? (int64_t *) Malloc(attlen * sizeof(int64_t)) : &attint64;
       cdfGetAttInt64(ncid, ncvarid, attname, attlen, pattint64);
       bool defineAtts = true;
       for (size_t i = 0; i < attlen; ++i)
@@ -891,7 +891,7 @@ cdf_set_cdi_attr(int ncid, int ncvarid, int attnum, int cdiID, int varID, bool r
       if (defineAtts)
         {
           int attint = 0;
-          int *pattint = (attlen > 1) ? Malloc(attlen * sizeof(int)) : &attint;
+          int *pattint = (attlen > 1) ? (int *) Malloc(attlen * sizeof(int)) : &attint;
           for (size_t i = 0; i < attlen; ++i) pattint[i] = (int) pattint64[i];
           cdiDefAttInt(cdiID, varID, attname, CDI_DATATYPE_INT32, (int) attlen, pattint);
           if (attlen > 1) Free(pattint);
@@ -901,7 +901,7 @@ cdf_set_cdi_attr(int ncid, int ncvarid, int attnum, int cdiID, int varID, bool r
   else if (xtypeIsFloat(atttype))
     {
       double attflt = 0.0;
-      double *pattflt = (attlen > 1) ? Malloc(attlen * sizeof(double)) : &attflt;
+      double *pattflt = (attlen > 1) ? (double *) Malloc(attlen * sizeof(double)) : &attflt;
       cdfGetAttDouble(ncid, ncvarid, attname, attlen, pattflt);
       int datatype = (atttype == NC_FLOAT) ? CDI_DATATYPE_FLT32 : CDI_DATATYPE_FLT64;
       cdiDefAttFlt(cdiID, varID, attname, datatype, (int) attlen, pattflt);
@@ -4315,14 +4315,14 @@ cdf_read_timesteps(size_t numTimesteps, stream_t *streamptr, taxis_t *taxis0)
       int nctimeboundsid = streamptr->basetime.ncvarboundsid;
       bool hasTimesteps = (nctimevarid != CDI_UNDEFID && streamptr->basetime.hasUnits);
 
-      int *ncStepIndices = Malloc(numTimesteps * sizeof(int));
+      int *ncStepIndices = (int *) Malloc(numTimesteps * sizeof(int));
       for (size_t tsID = 0; tsID < numTimesteps; ++tsID) ncStepIndices[tsID] = (int) tsID;
 
       CdiDateTime *vDateTimeList = NULL;
 
       if (hasTimesteps)
         {
-          vDateTimeList = Malloc(numTimesteps * sizeof(CdiDateTime));
+          vDateTimeList = (CdiDateTime *) Malloc(numTimesteps * sizeof(CdiDateTime));
 
           if (streamptr->basetime.isWRF)
             {
@@ -4331,7 +4331,7 @@ cdf_read_timesteps(size_t numTimesteps, stream_t *streamptr, taxis_t *taxis0)
             }
           else
             {
-              double *timevarBuffer = Malloc(numTimesteps * sizeof(double));
+              double *timevarBuffer = (double *) Malloc(numTimesteps * sizeof(double));
               cdf_get_var_double(fileID, nctimevarid, timevarBuffer);
               for (size_t tsID = 0; tsID < numTimesteps; ++tsID)
                 vDateTimeList[tsID] = cdi_decode_timeval(get_timevalue(fileID, nctimevarid, tsID, timevarBuffer), taxis0);
diff --git a/src/stream_cdf_o.c b/src/stream_cdf_o.c
index b89630b4f5b744e3b89fa46286b74b1e8ef3bbaf..cd07f30a2ee6fd274b897e31f13807d947e0f8b6 100644
--- a/src/stream_cdf_o.c
+++ b/src/stream_cdf_o.c
@@ -654,7 +654,7 @@ cdfDefAxisCommon(stream_t *streamptr, int gridID, int gridIndex, int ndims, bool
               const double *pvals = gridAxisInq->axisValsPtr(gridID);
               genBounds = true;
               nvertex = 2;
-              pbounds = Malloc(2 * (size_t) dimlen * sizeof(double));
+              pbounds = (double *) Malloc(2 * (size_t) dimlen * sizeof(double));
               for (size_t i = 0; i < (size_t) dimlen - 1; ++i)
                 {
                   pbounds[i * 2 + 1] = (pvals[i] + pvals[i + 1]) * 0.5;
@@ -1456,7 +1456,7 @@ cdf_def_zaxis_hybrid_cf(stream_t *streamptr, int type, int *ncvaridp, int zaxisI
   int ncbvarid = CDI_UNDEFID;
   int nvdimID = CDI_UNDEFID;
 
-  double *buffer = Malloc(2 * dimlen * sizeof(double));
+  double *buffer = (double *) Malloc(2 * dimlen * sizeof(double));
   double *lbounds = buffer;
   double *ubounds = buffer + dimlen;
   double *restrict levels;
@@ -1466,7 +1466,7 @@ cdf_def_zaxis_hybrid_cf(stream_t *streamptr, int type, int *ncvaridp, int zaxisI
     levels = (double *) zaxisInqLevelsPtr(zaxisID);
   else
     {
-      levels = Malloc(sizeof(*levels) * dimlen);
+      levels = (double *) Malloc(sizeof(*levels) * dimlen);
       for (size_t i = 0; i < dimlen; ++i) levels[i] = (double) (i + 1);
     }
 
@@ -1535,7 +1535,7 @@ cdf_def_zaxis_hybrid_cf(stream_t *streamptr, int type, int *ncvaridp, int zaxisI
 
   if (ncbvarid != CDI_UNDEFID)
     {
-      double *restrict zbounds = Malloc(2 * dimlen * sizeof(*zbounds));
+      double *zbounds = (double *) Malloc(2 * dimlen * sizeof(*zbounds));
       for (size_t i = 0; i < dimlen; ++i)
         {
           zbounds[2 * i] = lbounds[i];
@@ -1804,8 +1804,8 @@ cdfDefZaxis(stream_t *streamptr, int zaxisID)
                     cdf_put_att_text(fileID, ncvarid, "bounds", axisnameLen + sizeof(bndsName), axisname);
                   }
                   {
-                    double *restrict zbounds = (double *) Malloc(4 * dimlen * sizeof(*zbounds)),
-                                     *restrict lbounds = zbounds + 2 * dimlen, *restrict ubounds = zbounds + 3 * dimlen;
+                    double *zbounds = (double *) Malloc(4 * dimlen * sizeof(*zbounds)), *lbounds = zbounds + 2 * dimlen,
+                           *ubounds = zbounds + 3 * dimlen;
                     zaxisInqLbounds(zaxisID, lbounds);
                     zaxisInqUbounds(zaxisID, ubounds);
                     for (size_t i = 0; i < dimlen; ++i)
@@ -2033,7 +2033,7 @@ cdfDefReducedGrid(stream_t *streamptr, int gridID, int gridIndex)
         cdf_enddef(fileID, streamptr->self);
         streamptr->ncmode = 2;
 
-        int *reducedPoints = Malloc((size_t) dimlen * sizeof(int));
+        int *reducedPoints = (int *) Malloc((size_t) dimlen * sizeof(int));
         gridInqReducedPoints(gridID, reducedPoints);
         cdf_put_var_int(fileID, ncvarid, reducedPoints);
         Free(reducedPoints);
@@ -2248,7 +2248,7 @@ cdfDefCoordinateVars(stream_t *streamptr)
 
   struct cdfPostDefActionList *delayed = NULL;
 
-  ncgrid_t *restrict ncgrid = streamptr->ncgrid;
+  ncgrid_t *ncgrid = streamptr->ncgrid;
   for (int index = 0; index < 2 * ngrids; ++index)
     {
       ncgrid[index].gridID = CDI_UNDEFID;
diff --git a/src/stream_cgribex.c b/src/stream_cgribex.c
index cd7921a37ad95bd70596f1089635e67de5ac9cc8..c625dc10d9b62169b875586a2cf909c6bd0166d8 100644
--- a/src/stream_cgribex.c
+++ b/src/stream_cgribex.c
@@ -2075,7 +2075,7 @@ cgribexEncode(int memtype, int varID, int levelID, int vlistID, int gridID, int
   if (sec2len > cgribexp->sec2len)
     {
       cgribexp->sec2len = sec2len;
-      cgribexp->sec2 = Realloc(cgribexp->sec2, sec2len * sizeof(int));
+      cgribexp->sec2 = (int *) Realloc(cgribexp->sec2, sec2len * sizeof(int));
     }
 
   int *isec0 = cgribexp->sec0;
diff --git a/src/stream_gribapi.c b/src/stream_gribapi.c
index f5a0d504c0202e396593096cf9f8ef26a0b297f7..994230ff7ebd48416815beb7f2930a3e7853f889 100644
--- a/src/stream_gribapi.c
+++ b/src/stream_gribapi.c
@@ -2226,7 +2226,7 @@ gribapiDefGridRegular(grib_handle *gh, int gridID, int gridtype, bool gridIsRota
 
       nlon = 0;
 
-      long *pl = Malloc((size_t) nlat * sizeof(long) + (size_t) nlat * sizeof(int));
+      long *pl = (long *) Malloc((size_t) nlat * sizeof(long) + (size_t) nlat * sizeof(int));
       int *reducedPoints = (int *) (pl + nlat);
       gridInqReducedPoints(gridID, reducedPoints);
       for (long i = 0; i < nlat; ++i) pl[i] = reducedPoints[i];
@@ -3432,7 +3432,7 @@ gribapiEncode(int memType, int varID, int levelID, int vlistID, int gridID, int
         {
           grib_set_long(gh, "grib2LocalSectionPresent", 1);
           grib_set_long(gh, "grib2LocalSectionNumber", grib2LocalSectionNumber);
-          unsigned char *section2Padding = Malloc((size_t) section2PaddingLength);
+          unsigned char *section2Padding = (unsigned char *) Malloc((size_t) section2PaddingLength);
           cdiInqKeyBytes(vlistID, varID, CDI_KEY_SECTION2PADDING, section2Padding, &section2PaddingLength);
           size_t len = (size_t) section2PaddingLength;
           // Does not work anymore with ecCodes 2.22.0/2.25.0!!!
diff --git a/src/stream_record.c b/src/stream_record.c
index 3c8bfda60662c2e96a58610360214d24984088d6..a8c6b3ec9818da91aba3d70563e335345c8d2aa1 100644
--- a/src/stream_record.c
+++ b/src/stream_record.c
@@ -51,7 +51,7 @@ recordNewEntry(stream_t *streamptr, int tsID)
   else  // Create the table the first time through.
     {
       recordSize = 1;  //  <<<<----
-      records = Malloc((size_t) recordSize * sizeof(record_t));
+      records = (record_t *) Malloc((size_t) recordSize * sizeof(record_t));
       for (int i = recordID; i < recordSize; i++) records[i].used = CDI_UNDEFID;
     }
 
@@ -63,7 +63,7 @@ recordNewEntry(stream_t *streamptr, int tsID)
       else if (recordSize < INT_MAX)      recordSize = INT_MAX;
       else Error("Cannot handle this many records!\n");
       // clang-format on
-      records = Realloc(records, (size_t) recordSize * sizeof(record_t));
+      records = (record_t *) Realloc(records, (size_t) recordSize * sizeof(record_t));
 
       for (int i = recordID; i < recordSize; i++) records[i].used = CDI_UNDEFID;
     }
diff --git a/src/stream_write.c b/src/stream_write.c
index a29929affc7506c51474ffba6c2c3901df0a1f21..4383cb782b7d3883762bc4ecf426782d071cc3fa 100644
--- a/src/stream_write.c
+++ b/src/stream_write.c
@@ -111,7 +111,7 @@ streamWriteVarF(int streamID, int varID, const float *data, SizeType numMissVals
       const int vlistID = streamInqVlist(streamID);
       SizeType elementCount = gridInqSize(vlistInqVarGrid(vlistID, varID));
       elementCount *= (SizeType) zaxisInqSize(vlistInqVarZaxis(vlistID, varID));
-      double *conversionBuffer = Malloc((size_t) elementCount * sizeof(*conversionBuffer));
+      double *conversionBuffer = (double *) Malloc((size_t) elementCount * sizeof(*conversionBuffer));
       for (SizeType i = elementCount; i--;) conversionBuffer[i] = data[i];
       myCdiStreamWriteVar_(streamID, varID, MEMTYPE_DOUBLE, (const void *) conversionBuffer, numMissVals);
       Free(conversionBuffer);
@@ -210,7 +210,7 @@ streamWriteVarSliceF(int streamID, int varID, int levelID, const float *data, Si
       // In case the file format does not support single precision writing,
       // we fall back to double precision writing, converting the data on the fly.
       const SizeType elementCount = gridInqSize(vlistInqVarGrid(streamInqVlist(streamID), varID));
-      double *conversionBuffer = Malloc((size_t) elementCount * sizeof(*conversionBuffer));
+      double *conversionBuffer = (double *) Malloc((size_t) elementCount * sizeof(*conversionBuffer));
       for (SizeType i = elementCount; i--;) conversionBuffer[i] = (double) data[i];
       streamWriteVarSlice(streamID, varID, levelID, conversionBuffer, numMissVals);
       Free(conversionBuffer);
diff --git a/src/subtype.c b/src/subtype.c
index 47ffcc2af11dc1be9da6e4ebbe3bb38bd7e7b7e7..ec5a7be5a314269db82905184e59529390a5d777 100644
--- a/src/subtype.c
+++ b/src/subtype.c
@@ -788,13 +788,6 @@ subtypeInqAttribute(int subtypeID, int index, const char *key, int *outValue)
              subtype_ptr->nentries, index);
     }
 
-#ifndef __cplusplus
-  if (!outValue) outValue = &(int){ 0 };
-#else
-  int dummy = 0;
-  if (!outValue) outValue = &dummy;
-#endif
-
   if (!key) return CDI_EINVAL;
   int iKey = attribute_to_index(key);
   if (iKey < 0) return CDI_EINVAL;
@@ -809,7 +802,7 @@ subtypeInqAttribute(int subtypeID, int index, const char *key, int *outValue)
     {
       if (attribute->key == iKey)
         {
-          *outValue = attribute->val;
+          if (outValue) *outValue = attribute->val;
           return CDI_NOERR;
         }
     }
diff --git a/src/tsteps.c b/src/tsteps.c
index 2704728c35c58b2297d1da881ad8147b27fe004a..7a22bd24830f69e86993eb41c1e537f8d98a5cc7 100644
--- a/src/tsteps.c
+++ b/src/tsteps.c
@@ -70,7 +70,7 @@ cdi_create_timesteps(size_t numTimesteps, stream_t *streamptr)
 
   size_t ntsteps = (numTimesteps == 0) ? 1 : numTimesteps;
 
-  streamptr->tsteps = Malloc(ntsteps * sizeof(tsteps_t));
+  streamptr->tsteps = (tsteps_t *) Malloc(ntsteps * sizeof(tsteps_t));
 
   streamptr->tstepsTableSize = (int) ntsteps;
   streamptr->tstepsNextID = (int) ntsteps;
diff --git a/src/varscan.c b/src/varscan.c
index 7a35514033a09c5239d2624b455982ec53fab96f..f38de021200d2ab31cb97f54fd43d3d85d4a46d2 100644
--- a/src/varscan.c
+++ b/src/varscan.c
@@ -500,7 +500,7 @@ cdi_generate_vars(stream_t *streamptr)
 {
   int vlistID = streamptr->vlistID;
 
-  int *varids = Malloc((size_t) varTableUsed * sizeof(int));
+  int *varids = (int *) Malloc((size_t) varTableUsed * sizeof(int));
   for (int varID = 0; varID < varTableUsed; varID++) varids[varID] = (int) varID;
   /*
     if (streamptr->sortname)
@@ -582,7 +582,7 @@ cdi_generate_vars(stream_t *streamptr)
 
       if (ltype1 == 0 && zaxistype == ZAXIS_GENERIC && nlevels == 1 && levelTable[0].level1 == 0) zaxistype = ZAXIS_SURFACE;
 
-      double *dlevels = Malloc((size_t) nlevels * sizeof(double));
+      double *dlevels = (double *) Malloc((size_t) nlevels * sizeof(double));
 
       /*
       if ( hasBounds && zaxistype != ZAXIS_HYBRID && zaxistype != ZAXIS_HYBRID_HALF )
@@ -638,7 +638,7 @@ cdi_generate_vars(stream_t *streamptr)
       double *dlevels1 = NULL, *dlevels2 = NULL;
       if (hasBounds)
         {
-          dlevels1 = Malloc(2 * (size_t) nlevels * sizeof(double));
+          dlevels1 = (double *) Malloc(2 * (size_t) nlevels * sizeof(double));
           dlevels2 = dlevels1 + nlevels;
           for (int levelID = 0; levelID < nlevels; levelID++) dlevels1[levelID] = level_sf * levelTable[levelID].level1;
           for (int levelID = 0; levelID < nlevels; levelID++) dlevels2[levelID] = level_sf * levelTable[levelID].level2;
@@ -800,7 +800,7 @@ zaxis_compare(int zaxisID, int zaxistype, int nlevels, const double *levels, con
 
           if (!differ && hasBounds)
             {
-              double *bounds = Malloc(2 * (size_t) nlevels * sizeof(double));
+              double *bounds = (double *) Malloc(2 * (size_t) nlevels * sizeof(double));
               zaxisInqLbounds(zaxisID, bounds);
               zaxisInqUbounds(zaxisID, bounds + nlevels);
               for (int levelID = 0; levelID < nlevels; levelID++)
diff --git a/src/vlist.c b/src/vlist.c
index 5501f4ace60e64a8b7f934c587d7be5253a4537d..a74e284ccf08bfdd93fce0f23ab0d860eef21d21 100644
--- a/src/vlist.c
+++ b/src/vlist.c
@@ -67,16 +67,12 @@ static int vlistGetSizeP(void *vlistptr, void *context);
 static void vlistPackP(void *vlistptr, void *buff, int size, int *position, void *context);
 static int vlistTxCode(void *vlistptr);
 
-#if !defined(__cplusplus)
-const
-#endif
-    resOps vlistOps
-    = { (valCompareFunc) vlist_compare,
-        (valDestroyFunc) vlist_delete,
-        (valPrintFunc) vlistPrintKernel,
-        vlistGetSizeP,
-        vlistPackP,
-        vlistTxCode };
+const resOps vlistOps = { (valCompareFunc) vlist_compare,
+                          (valDestroyFunc) vlist_delete,
+                          (valPrintFunc) vlistPrintKernel,
+                          vlistGetSizeP,
+                          vlistPackP,
+                          vlistTxCode };
 
 vlist_t *
 vlist_to_pointer(int vlistID)
diff --git a/src/vlist.h b/src/vlist.h
index 0d220d1eae588a9f5d509cbf1aa7e10b92892e2f..e6775b4a5ba5111f0cbf0599b9dc1043d2b36b9f 100644
--- a/src/vlist.h
+++ b/src/vlist.h
@@ -177,11 +177,7 @@ extern int cdiNAdditionalGRIBKeys;
 extern char *cdiAdditionalGRIBKeys[];
 #endif
 
-extern
-#ifndef __cplusplus
-    const
-#endif
-    resOps vlistOps;
+extern const resOps vlistOps;
 
 #endif /* VLIST_H */
 /*
diff --git a/src/vlist_var_pack.c b/src/vlist_var_pack.c
index 901c60ee07d4e4a073cd3d9d1da2954c1a1ec1ac..5395ac74a239ee78d2618f1d28aa0301bf1dceb1 100644
--- a/src/vlist_var_pack.c
+++ b/src/vlist_var_pack.c
@@ -86,7 +86,7 @@ vlistVarPack(vlist_t *p, int varID, char *buf, int size, int *position, void *co
   }
   if (nlevs)
     {
-      int *levbuf = Malloc((size_t) nlevs * sizeof(int));
+      int *levbuf = (int *) Malloc((size_t) nlevs * sizeof(int));
       for (int levID = 0; levID < nlevs; ++levID) levbuf[levID] = var->levinfo[levID].flag;
       serializePack(levbuf, nlevs, CDI_DATATYPE_INT, buf, size, position, context);
       for (int levID = 0; levID < nlevs; ++levID) levbuf[levID] = var->levinfo[levID].index;
@@ -134,7 +134,7 @@ vlistVarUnpack(int vlistID, char *buf, int size, int *position, int originNamesp
       int i, flagSetLev = 0;
       cdiVlistCreateVarLevInfo(vlistptr, newvar);
 
-      int *levbuf = Malloc((size_t) nlevs * sizeof(int));
+      int *levbuf = (int *) Malloc((size_t) nlevs * sizeof(int));
       serializeUnpack(buf, size, position, levbuf, nlevs, CDI_DATATYPE_INT, context);
       for (i = 0; i < nlevs; ++i) vlistDefFlag(vlistID, newvar, i, levbuf[i]);
       for (i = 0; i < nlevs; ++i)
diff --git a/tests/cksum_read.c b/tests/cksum_read.c
index fe6a70717e81c39fd03fc09f8c7ba071180bb1aa..77cf0eb32492b8fde8b607ac472327f046f019a9 100644
--- a/tests/cksum_read.c
+++ b/tests/cksum_read.c
@@ -11,10 +11,6 @@
 #include "var_cksum.h"
 #include "stream_cksum.h"
 
-#ifdef __cplusplus
-#define PRIx32 ""
-#endif
-
 static struct cksum_table *
 read_table(const char *table_fname, size_t *table_len)
 {
diff --git a/tests/pio_write.c b/tests/pio_write.c
index 8d65aa69ed12cf0462630b4434b5585248b76e5d..18355232edb9cb09e1186d2a6bba909c6415a69e 100644
--- a/tests/pio_write.c
+++ b/tests/pio_write.c
@@ -33,36 +33,20 @@
 
 static const char default_fname_prefix[] = "example";
 
-static const struct model_config default_setup
-#ifdef __cplusplus
-    = { 12,
-        6,
-        3,
-        5,
-        5,
-        CDI_FILETYPE_GRB,
-        CDI_DATATYPE_PACK24,
-        PIO_WRITE_CONFIG_CHECKSUM_FLAG,
-        TAXIS_ABSOLUTE,
-        -1,
-        "grb",
-        default_fname_prefix };
-#else
-    = {
-        .nlon = 12,
-        .nlat = 6,
-        .nts = 3,
-        .max_nlev = 5,
-        .nvars = 5,
-        .filetype = CDI_FILETYPE_GRB,
-        .datatype = CDI_DATATYPE_PACK24,
-        .flags = PIO_WRITE_CONFIG_CHECKSUM_FLAG,
-        .taxistype = TAXIS_ABSOLUTE,
-        .taxisunit = -1,
-        .suffix = "grb",
-        .prefix = default_fname_prefix,
-      };
-#endif
+static const struct model_config default_setup = {
+  .nlon = 12,
+  .nlat = 6,
+  .nts = 3,
+  .max_nlev = 5,
+  .nvars = 5,
+  .filetype = CDI_FILETYPE_GRB,
+  .datatype = CDI_DATATYPE_PACK24,
+  .flags = PIO_WRITE_CONFIG_CHECKSUM_FLAG,
+  .taxistype = TAXIS_ABSOLUTE,
+  .taxisunit = -1,
+  .suffix = "grb",
+  .prefix = default_fname_prefix,
+};
 
 static const struct
 {
diff --git a/tests/pio_write_setup_grid.c b/tests/pio_write_setup_grid.c
index 8b35dc07aad3591928a11ad764cab49b940e822d..e250a643bb2d76894822e41805d076126646fe58 100644
--- a/tests/pio_write_setup_grid.c
+++ b/tests/pio_write_setup_grid.c
@@ -133,18 +133,10 @@ setupGrid(const struct model_config *setup, MPI_Comm comm)
           {
             double *grid_chunk = (double *) Malloc(2 * grid_chunk_size * sizeof(*grid_chunk));
             /* anti-clockwise coordinates around Amazonia */
-            static const struct cart_coord region[4]
-#ifdef __cplusplus
-                = { { DEG2RAD(-25.0), DEG2RAD(-85.0) },
-                    { DEG2RAD(-18.0), DEG2RAD(-44.0) },
-                    { DEG2RAD(-7.0), DEG2RAD(-50.0) },
-                    { DEG2RAD(10.0), DEG2RAD(-80.0) } };
-#else
-                = { { .lon = DEG2RAD(-85.0), .lat = DEG2RAD(-25.0) },
-                    { .lon = DEG2RAD(-44.0), .lat = DEG2RAD(-18.0) },
-                    { .lon = DEG2RAD(-50.0), .lat = DEG2RAD(7.0) },
-                    { .lon = DEG2RAD(-80.0), .lat = DEG2RAD(10.0) } };
-#endif
+            static const struct cart_coord region[4] = { { .lon = DEG2RAD(-85.0), .lat = DEG2RAD(-25.0) },
+                                                         { .lon = DEG2RAD(-44.0), .lat = DEG2RAD(-18.0) },
+                                                         { .lon = DEG2RAD(-50.0), .lat = DEG2RAD(7.0) },
+                                                         { .lon = DEG2RAD(-80.0), .lat = DEG2RAD(10.0) } };
             const size_t xyRange[2][2] = { { (size_t) grid_local_chunk_start[1], (size_t) grid_local_chunk_start[0] },
                                            { (size_t) grid_local_chunk_shape[1], (size_t) grid_local_chunk_shape[0] } };
             computeCurvilinearChunk(grid_chunk, region, (size_t) nlon, (size_t) nlat, xyRange);
diff --git a/tests/simple_model_helper.c b/tests/simple_model_helper.c
index b660c7fde3686d3ad9cd13bd2ec2feb8ab56d011..774ac1092b02fc0e5a58b06652c47639a8ad1ff1 100644
--- a/tests/simple_model_helper.c
+++ b/tests/simple_model_helper.c
@@ -76,7 +76,7 @@ void
 composeFilename(char **buf, const char *fname_prefix, int tfID, const char *suffix)
 {
   size_t fnSize = strlen(fname_prefix) + (tfID >= 0 ? 1 + sizeof(int) * 3 : 0) + 1 + strlen(suffix) + 1;
-  char *filename = Realloc(*buf, fnSize);
+  char *filename = (char *) Realloc(*buf, fnSize);
   int plen = tfID >= 0 ? snprintf(filename, fnSize, "%s_%d.%s", fname_prefix, tfID, suffix)
                        : snprintf(filename, fnSize, "%s.%s", fname_prefix, suffix);
   if ((size_t) plen >= fnSize)
@@ -140,18 +140,10 @@ createLocalCurvilinearGrid(int sizex, int sizey)
   gridDefYsize(gridID, sizey);
   {
     /* anti-clockwise coordinates around Amazonia */
-    static const struct cart_coord region[4]
-#ifdef __cplusplus
-        = { { DEG2RAD(-25.0), DEG2RAD(-85.0) },
-            { DEG2RAD(-18.0), DEG2RAD(-44.0) },
-            { DEG2RAD(-7.0), DEG2RAD(-50.0) },
-            { DEG2RAD(10.0), DEG2RAD(-80.0) } };
-#else
-        = { { .lon = DEG2RAD(-85.0), .lat = DEG2RAD(-25.0) },
-            { .lon = DEG2RAD(-44.0), .lat = DEG2RAD(-18.0) },
-            { .lon = DEG2RAD(-50.0), .lat = DEG2RAD(7.0) },
-            { .lon = DEG2RAD(-80.0), .lat = DEG2RAD(10.0) } };
-#endif
+    static const struct cart_coord region[4] = { { .lon = DEG2RAD(-85.0), .lat = DEG2RAD(-25.0) },
+                                                 { .lon = DEG2RAD(-44.0), .lat = DEG2RAD(-18.0) },
+                                                 { .lon = DEG2RAD(-50.0), .lat = DEG2RAD(7.0) },
+                                                 { .lon = DEG2RAD(-80.0), .lat = DEG2RAD(10.0) } };
     double(*gridCoords)[sizey][sizex] = (double(*)[sizey][sizex]) Malloc(sizeof(*gridCoords) * gridsize * 2);
     {
       const size_t xyRange[2][2] = { { 0, 0 }, { (size_t) sizex, (size_t) sizey } };
@@ -178,7 +170,7 @@ intermediateCoord(struct cart_coord p1, struct cart_coord p2, double f)
   double d = cartDistance(p1, p2), sine_of_d = sin(d), A = sin((1 - f) * d) / sine_of_d, B = sin(f * d) / sine_of_d,
          x = A * cos(p1.lat) * cos(p1.lon) + B * cos(p2.lat) * cos(p2.lon),
          y = A * cos(p1.lat) * sin(p1.lon) + B * cos(p2.lat) * sin(p2.lon), z = A * sin(p1.lat) + B * sin(p2.lat);
-  struct cart_coord ic = { .lat = atan2(z, sqrt(x * x + y * y)), .lon = atan2(y, x) };
+  struct cart_coord ic = { .lon = atan2(y, x), .lat = atan2(z, sqrt(x * x + y * y)) };
   return ic;
 }
 
@@ -232,7 +224,7 @@ int
 PPM_prime_factorization_32(uint32_t n, uint32_t **factors)
 {
   if (n <= 1) return 0;
-  uint32_t *restrict pfactors = Realloc(*factors, 32 * sizeof(pfactors[0]));
+  uint32_t *restrict pfactors = (uint32_t *) Realloc(*factors, 32 * sizeof(pfactors[0]));
   size_t numFactors = 0;
   uint32_t unfactored = n;
   while (!(unfactored & 1))
diff --git a/tests/simple_model_helper.h b/tests/simple_model_helper.h
index df0ffe3045709c63c460cd831df3f35e964715ac..85d315fbaf5921279313dc24832222ef907d2c1a 100644
--- a/tests/simple_model_helper.h
+++ b/tests/simple_model_helper.h
@@ -53,7 +53,7 @@ int createLocalCurvilinearGrid(int sizex, int sizey);
 
 struct cart_coord
 {
-  double lat, lon;
+  double lon, lat;
 };
 
 /*
diff --git a/tests/test_cdf_write.c b/tests/test_cdf_write.c
index 54e33fa0e2a58b7330aae042f477ab84c0f04b4b..71294affc5a50fac5ce4782ea914028247d0f46a 100644
--- a/tests/test_cdf_write.c
+++ b/tests/test_cdf_write.c
@@ -79,7 +79,7 @@ my_gamma_dist(double x)
   };
   const double theta = 0.5;
   x *= 20.0;
-  double pdf_x = 1.0 / (tgamma(k) * pow(theta, k)) * pow(x, k - 1) * exp(-x / theta);
+  double pdf_x = 1.0 / (tgamma((double)k) * pow(theta, k)) * pow(x, k - 1) * exp(-x / theta);
   return pdf_x;
 }