[petsc-dev] Request for comments: allow C99 internally

Jed Brown jed at jedbrown.org
Wed Mar 11 10:34:31 CDT 2020


My proposal is for PETSc to support the intersection of C99, C11, C++11,
and any later standards.  This (sadly*) excludes VLA.

[*] I don't care about stack allocation, but VLA-pointers are extremely
useful for multi-dimensional array indexing.  I'm sad that C11 made that
optional.

Jeff Hammond <jeff.science at gmail.com> writes:

> I wonder if it is not more useful to talk in terms of C11 features.  Unlike
> C99, C11 makes VLAs optional via __STDC_NO_VLA__, so you have a
> standardized way of expressing the subset of C11 that is compatible with
> C++11.  __STDC_NO_ATOMICS__ and __STDC_NO_THREADS__ play a similar role.
>
> Of course, some compilers refuse to use these properly, so PETSc will have
> to check compiler support directly rather than trusting macros, but that is
> nothing new and Jed (rightly) doesn't trust such compiler macros anyways.
> I merely suggest that the macros correspond to an ISO C language definition
> for describing the portable subset in a way that C99 cannot.

I don't think the macros are of any utility in defining the
intersection.  For example, g++ and clang++ do not set __STDC_NO_VLA__
(and aren't expected to because they aren't C compilers), yet they don't
support the syntax.

  double (*a)[n] = (double (*)[n])p;

  a[i][j] = 42;


More information about the petsc-dev mailing list