<div dir="ltr"><div><div dir="auto">Perhaps naively, I‘d assume that while there may well be someone out there relying on compilers for which this would be a problem, that same person is also less likely to be able to upgrade PETSc. </div></div><div dir="auto"><div dir="auto"><br></div><div dir="auto">The benefits seem well worth it. It‘ll make things just that much easier to work with. </div><div dir="auto"><br></div><div>+1 for the for-loop declarations.<br></div><div><br></div><div dir="auto">No more need to police the use of // C++-style comments?</div></div><div><br></div><div dir="auto"><br></div></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Jed Brown <<a href="mailto:jed@jedbrown.org" target="_blank">jed@jedbrown.org</a>> schrieb am Sa. 7. März 2020 um 06:48:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I have a question for petsc-dev: Do you know anyone who needs to build<br>
PETSc with a compiler that doesn't support variadic macros and for-loop<br>
declarations?  (Both of these are in C99 and C++11, and supported by all<br>
tested configurations including compilers that don't fully implement<br>
these standards.)  Both MPICH and Open MPI use variable-length arrays<br>
and for-loop declarations, so you'd be hard-pressed building a modern<br>
stack with such a compiler.  I'm not proposing that we put these macros<br>
unguarded into the public headers, so a user of PETSc could still build<br>
with -std=c89 and the like.<br>
<br>
<br>
## Background<br>
<br>
There is a common pattern in PETSc where we write<br>
<br>
  PetscInt some,several,variables;<br>
<br>
  // code<br>
#if defined(PETSC_HAVE_MAGIC)<br>
  function(several,&variables);<br>
#endif<br>
  use(some,variables);<br>
<br>
<br>
Of course this gives unused variable warnings, so we tear our code apart like<br>
<br>
  PetscInt some,variables;<br>
#if defined(PETSC_HAVE_MAGIC)<br>
  PetscInt several;<br>
#endif<br>
<br>
  // code<br>
#if defined(PETSC_HAVE_MAGIC)<br>
  function(several,&variables);<br>
#endif<br>
  use(some,variables);<br>
<br>
<br>
but the bigger problem is that we need different configurations just to<br>
check syntax of our compiled out blocks.  I propose allowing variadic<br>
macros (a C99 and C++11 feature) to allow code like<br>
<br>
  PetscInt some,several,variables;<br>
<br>
  // code<br>
  if (PetscDefined(HAVE_MAGIC)) {<br>
    function(several,&variables);<br>
  }<br>
  use(some,variables);<br>
<br>
<br>
This approach could also be used to avoid needing separate macros for<br>
every SETERRQ1-SETERRQ9, etc.  I have an example implementation in this<br>
MR, and it passes the full pipeline (after relaxing the -std=c89<br>
-pedantic build).<br>
<br>
<a href="https://gitlab.com/petsc/petsc/-/merge_requests/157/diffs" rel="noreferrer" target="_blank">https://gitlab.com/petsc/petsc/-/merge_requests/157/diffs</a><br>
<br>
<br>
We could also consider allowing for-loop declarations, which I believe<br>
leads to tighter and more understandable code because the reader doesn't<br>
have to wonder whether the variable is used after the loop.<br>
<br>
  for (PetscInt i=0; i<n; i++) { ... }<br>
<br>
<br>
Note that we cannot use variable-length arrays (VLA) because they are<br>
not in the intersection of C and C++.<br>
</blockquote></div></div>