change to petsc-dev
Lisandro Dalcin
dalcinl at gmail.com
Wed Jun 25 09:37:20 CDT 2008
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;
}
> 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
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?
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;
--
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