<div class="gmail_quote">On Wed, Dec 1, 2010 at 20:27, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div id=":23s">A more difficult example is that the Jacobian matrix argument to SNES is const (in some sense) but it is not to TS (since TS "adjusts" it before passing to SNES).<br></div></blockquote><div><br></div>
<div>This does not happen with TSComputeIJacobian, the user produces exactly what SNES needs.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div id=":23s">

  Note that "const" here may not have the strict C meaning of not changing anything in the object. For example VecNorm() is const on the vector elements but caches the computed norm so does change the data inside the object.</div>
</blockquote></div><br><div>This is easy to handle by casting internally.</div><div><br></div><div><br></div><div>The trouble is, of course, that once you typedef something,</div><div><br></div><div>typedef struct _p_Vec *Vec;</div>
<div><br></div><div>then "const Vec" just means that the pointer is const, not the struct behind it, thus the const keyword in</div><div><br></div><div>PetscErrorCode VecNorm(const Vec X,NormType,PetscReal*);</div>
<div><br></div><div>has exactly zero meaning as far as the interface is concerned.  Using</div><div><br></div><div>#define Vec struct _p_Vec*</div><div><br></div><div>instead of the typedef would cause the const to apply to the struct instead of the pointer, but this is really ugly for lots of reasons including (note that VecType already has this problem)</div>
<div><br></div><div>  Vec X,Y;   /* Y is a struct, yuck */</div><div><br></div><div>So the only way, within the C type system, to do what you want would be to</div><div><br></div><div>typedef const struct _p_Vec *const_Vec;</div>
<div><br></div><div>and then</div><div><br></div><div>PetscErrorCode VecNorm(const_Vec X,NormType,PetscReal*);</div><div><br></div><div>This works as you would expect, but it's an unconventional C style so I would be apprehensive about recommending it.</div>
<div><br></div><div>Jed</div>