[petsc-dev] declaring argument as const basic type in PETSc

Barry Smith bsmith at mcs.anl.gov
Wed Aug 17 14:55:30 CDT 2011


On Aug 17, 2011, at 2:50 PM, Chetan Jhurani wrote:

> I never meant to say that one must put const ints in the
> declaration.

   Our problem is that because one compiler warns if the const is not listed in both prototype and definition we must put it in both (to avoid tons of warning messages that people installing PETSc should not see) we MUST put them in the declaration. Which we wanted to avoid since it is anti-encapsulation.  So for now, they are forbidden in all PETSc code even though yes they can be useful in implementations.

   Barry

>  Whether it is there or not, the caller is not
> affected.
>  
> My point was const ints are useful on the developer side.
>  
> GNU Scientific Library and Intel and MKL use const ints for
> CBLAS function declarations.  Hadn’t noticed it earlier.
> I’ve seen it being used in professional closed source code.
> People stumble upon this idea unintentionally (because it
> has been working silently for a long time and not all
> compilers warn). And then some like it and some don’t.
>  
> Chetan
>  
>  
> From: petsc-dev-bounces at mcs.anl.gov [mailto:petsc-dev-bounces at mcs.anl.gov] On Behalf Of Jed Brown
> Sent: Wednesday, August 17, 2011 1:32 PM
> To: For users of the development version of PETSc
> Subject: Re: [petsc-dev] declaring argument as const basic type in PETSc
>  
> On Wed, Aug 17, 2011 at 12:29, Chetan Jhurani <chetan.jhurani at gmail.com> wrote:
> can be avoided by putting const int in declaration
> as well.
>  
> Right, but doing this is nonsense because it puts implementation details in a public header, the "anti-encapsulation". Just don't use const for value parameters.




More information about the petsc-dev mailing list