initialization of XXX_COOKIE in C source files
Barry Smith
bsmith at mcs.anl.gov
Sat May 10 19:49:34 CDT 2008
On May 10, 2008, at 6:08 PM, Lisandro Dalcin wrote:
> I've noticed that in 2.3.3 all PETSc cookies are initialized to zero
> in sources, but in DEV they are not initialized. What's the reason of
^^^^^^^^^^^^^^^^
You are quick, I just pushed the
change last night.
The reason why they where all initialized to zero was because
- a very long time ago all the cookies where hardwired numbers that we
chose for each new class
- then we added the ability to request a cookie, but still support the
old
hardwired version. Passing in a pointer to a zero value meant you
were
requesting one, passing in a pointer to a nonzero one meant that
the cookie
had a hardwired value.
- over time all the hardwired ones were unhardwired, but the convention
of initializing them to zero before hand was never changed.
There was some convoluted logic for why the PetscEvent values were
all initialized to zero also. When fixing up the events I also fixed
the cookies
The reason is Barry's rule # 54, "nothing should be done in a code
without
a reason, otherwise it will be confusing to others looking at the
code." For example,
even now, whenever anybody made some new events they initialized them
to zero, why? Not because they need to be, but simply because they
were in
code the developer copied from.
Were you taking advantage of their initialization to zero? If so,
rather than depending
on each cookie being initialized to zero I would suggest handling this
type
of "check if initialized" stuff at a package by package level or
library by library level.
Please let me know what you need.
Barry
>
> this change?
>
> --
> 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