[petsc-dev] reminder about initializing structs

Barry Smith bsmith at mcs.anl.gov
Thu Nov 21 21:30:27 CST 2013

On Nov 21, 2013, at 8:57 PM, Jed Brown <jedbrown at mcs.anl.gov> wrote:

> Barry Smith <bsmith at mcs.anl.gov> writes:
>>  You can’t do this in C89, so please don’t do this in PETSc code since someone (me, will have to fix it later) 
>> src/dm/impls/da/dalocal.c: In function ‘DMDASetVertexCoordinates’:
>> src/dm/impls/da/dalocal.c:1192:5: warning: initializer element is not computable at load time [enabled by default]
>>     PetscInt ind[3] = {0, 0, k + da->zs}, d, off;
> Do any compilers actually reject this, or only warn with -std=c89?  The
> struct syntax is more compact and easier to read.  I assume that
> Microsoft will eventually completely drop support for their C compiler,
> and then there will be no reason not to use basic C99 features.

   Since it is not computable presumably it will not produce correct values. 

   The thing is if we start dropping this stuff in then we cannot use the -std-c89 flag so we cannot consistently check for no c89 constructs (or we get warnings all of the code that we cannot distinguish from real warnings. 

    It is a tiny bit of syntactic sugar that is not worth the drawbacks of warnings and or not checking source code so please don’t put it in.


More information about the petsc-dev mailing list