On Thu, Jun 2, 2011 at 21:49, Roy Stogner <[email protected]> wrote:

> are we some kind of oddball
> nitpickers for using the const keyword in math software?
>

PETSc uses const for all array arguments that are const. If any are missing,
it's a bug. PETSc does not use const for typedefs because of the language
(scope of const as it applies to typedefs). To have a const-correct API, we
would either need to create a bunch of const_Vec, const_Mat, etc. typedefs
(and have users know that a Mat would be implicitly converted to a
const_Mat, but not vice-versa) or

typedef struct _p_Vec Vec;

(no "*") and make everyone add a "*" everywhere in their code. The last
"alternative" of

#define Vec struct _p_Vec*

instead of a typedef is atrocious because the declaration "Vec X,Y" would be
incorrect because Y would be allocated as a private struct instead of
pointer.

> Actually, what's wrong with "const" is that the compiler *can't* use
it for efficiency.

An exception: statically allocated const objects (most frequently arrays of
strings and v-tables) are placed in read-only memory which reduces binary
size and loading time.

Const is for people. The restrict qualifier, on the other hand ...
------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Discover what all the cheering's about.
Get your free trial download today. 
http://p.sf.net/sfu/quest-dev2dev2 
_______________________________________________
Libmesh-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libmesh-users

Reply via email to