change to petsc-dev

Barry Smith bsmith at mcs.anl.gov
Wed Jun 25 10:32:11 CDT 2008


On Jun 25, 2008, at 9:37 AM, Lisandro Dalcin wrote:

> On 6/24/08, Barry Smith <bsmith at mcs.anl.gov> wrote:
>> Actually I consider that I added the const to make the compiler happy
>> without really
>> understanding what I was doing with const (I still don't completely
>> understand const).
>
> Well, at least you understand why the program below segfaults, right?
>
> static void myfun(char* p) {
>  p[0] = 'Z';
> }
> int main() {
>  myfun("Lisandro");
>  return 0;
> }
>
>
    Yes, this is the simplest use of const. I understand this case.

>> Somehow Matt and Lisandro seem to think my "fix" of adding
>> const to VecType (and XXType) was fundamentally correct;
>> I think it was just a result of my stupidity.
>
> I still think the const was fundamentally correct, at least if you
> want VecType to be like an 'opaque' handle  being employed on the USER
                                                      ^^^^^^^^^^^^
      I never saw these as 'opaque' handles, I always saw them as  
'names'
of object types.

>
> side. If you think about XXXTypes being opaque handles, then having to
> declare a 'const XXXType' variable is confusing, unnatural, and ugly.
>
>
>
>> We can easily eliminate the XXType completely and just have
>> XXXSetType(XXX,const char *)
>> then one could do
>> const char *vtype = VECMPI;
>> instead of
>> const VecType vtype = VECMPI;
>>
>> Perhaps this is best, I introduced XXXType just to make the code more
>> transparent,
>
> IMHO, XXXType (the const form) makes the USER-level code cleaner.
> Additionally, it make more explicit the prototipes of PETSc routines.
>
> Consider this:
>
> (1) PetscErrorCode DMGetMatrix(DM, MatType, Mat*);
>
> against this:
>
> (2) PetscErrorCode DMGetMatrix(DM, const char*, Mat*);
>
>
> Do you think (2) makes clear what the pourpose of the 'const char*'  
> argument is?

    Clearly 1 is clearer, which is why I introduced the XXType.
>
>
> And the same reasoning could be applied to VecLoad, MatLoad,
> MatConvert, MatGetOrdering, etc.
>
> So I still convinced that all XXX types should be a typedef with const
> (NOT a #define) like this:
>
> typedef const char* XXXType;
>
>
      I can understand your point of view; as Satish says it is a  
tradeoff
of competing issues.

    Barry

>
>
>
> -- 
> Lisandro Dalcín
> ---------------
> Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
> Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
> Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
> PTLC - Güemes 3450, (3000) Santa Fe, Argentina
> Tel/Fax: +54-(0)342-451.1594
>




More information about the petsc-dev mailing list