[petsc-dev] Compliant C89

Matthew Knepley knepley at gmail.com
Mon Jan 14 11:33:31 CST 2013


On Mon, Jan 14, 2013 at 11:17 AM, Barry Smith <bsmith at mcs.anl.gov> wrote:

>
> On Jan 14, 2013, at 9:02 AM, Jed Brown <jedbrown at mcs.anl.gov> wrote:
>
> > The cast macros like PetscBLASIntCast() are not "safe" in that they
> include two separate statements. Unfortunately, we cannot do better with
> C89 unless we pass the target as an argument. Regardless, these casts
> cannot be used in declarations.
> >
> > PetscBLASInt   one = 1,bn = PetscBLASIntCast(xin->map->n);
> > PetscErrorCode ierr;
> >
> > This is invalid C89 because once the macro expands, there is a statement
> before the next declaration. Furthermore, the check calls SETERRQ in case
> of failure, so it must be inside a PetscFunctionBegin/PetscFunctionReturn
> block.
> >
> > Should we change this cast to an inline function (or equivalent macro)
> so that this usage is more explicit?
>
>   Note that even if you change it to an inline function it still will not
> give the correct stack frame since it is not inside the
> PetscFunctionBegin/End.
>
>   Shouldn't we simply ban its use in the declarations part of the
> routines? Note that its use in, for example,
>
>     } else {
>       PetscBLASInt ione = 1;
>       PetscScalar aone = 1.0, azero = 0.0;
>       PetscBLASInt neqs = PetscBLASIntCast(bcgsl->ell-1);
>
> is legal since it is within a PetscBegin/Return block and the last
> declaration given.
>
> A quick etags search found that it is being used correctly already almost
> anywhere. The suspicious place is only in the documentation :-)
>
> Thus I say, fix the documentation and check that it is never used
> incorrectly but don't change its form.


I completely disagree. This is very misleading. Something named *Cast()
which does not actually behave as a cast,
and only breaks on some compilers? Are we purposely trying to confuse new
developers?

   Matt


>
>   Barry
>
> >
> > Regardless, Satish, can you set up a build --with-64-bit-indices
> CFLAGS='-std=c89 -pedantic -Wno-long-long'?
>
>


-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20130114/4546618d/attachment.html>


More information about the petsc-dev mailing list