On Wed, Aug 17, 2011 at 10:13 PM, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im"><br>
On Aug 17, 2011, at 3:08 PM, Matthew Knepley wrote:<br>
<br>
> On Wed, Aug 17, 2011 at 10:05 PM, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> wrote:<br>
><br>
> Because it exposes a completely implementation detail to the public interface, (unnecessarily at that) So yes it is for philosophical reasons that we must reject this badly designed C standard.<br>
><br>
> So you are saying that, according to the standard (Jed will certainly have a reference), that some value parameter<br>
> declared as const can be assigned to in the function? If that is so, it is full of crap. Every compiler I have used bombed<br>
> on that, and (lacking real authority) during my Google interview they thought this was good practice.<br>
<br>
</div> No I am not saying that. Not even close, how could you possibly have gotten that from the sentence "Because it exposes a completely implementation detail to the public interface, (unnecessarily at that) So yes it is for philosophical reasons that we must reject this badly designed C standard."</blockquote>
<div><br></div><div>This way. You said it was a "completely implementation detail", from which I supposed that different compilers were allowed</div><div>to interpret it as they see fit (thats what I thought an implementation detail was). I asked for confirmation on this: "does the</div>
<div>standard allow a 'const' parameter to be assigned to?", since I know every compiler I have tried does not allow this. I thought</div><div>your philosophical reason was that the standard allows a 'const' value declaration, but enforces nothing. Is this wrong?</div>
<div><br></div><div> MAtt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><font color="#888888"><br>
Barry<br>
</font><div><div></div><div class="h5"><br>
><br>
> Matt<br>
><br>
><br>
> Barry<br>
><br>
><br>
> On Aug 17, 2011, at 2:58 PM, Matthew Knepley wrote:<br>
><br>
> > On Wed, Aug 17, 2011 at 9:08 PM, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> wrote:<br>
> ><br>
> > On Aug 17, 2011, at 2:04 PM, Chetan Jhurani wrote:<br>
> ><br>
> > >> From: Jed Brown<br>
> > >> Sent: Wednesday, August 17, 2011 12:38 PM<br>
> > >> To: For users of the development version of PETSc<br>
> > >> Subject: Re: [petsc-dev] declaring argument as const basic type in PETSc<br>
> > >><br>
> > >> On Wed, Aug 17, 2011 at 11:34, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> wrote:<br>
> > >>> But my question remains, should we const declare function arguments?<br>
> > >><br>
> > >> No, the prototype should never use const for stack arguments (pointer to const<br>
> > >> is totally different and should be used anywhere that it is correct).<br>
> > >><br>
> > >> I don't know any responsible libraries that const-ify value parameters in<br>
> > >> prototypes. I think it most commonly arises from ignorance of, or sloppiness<br>
> > >> with, the actual semantics of the C language.<br>
> > ><br>
> > ><br>
> > So by the standard a compiler should never bitch if in the function definition it is declared const but in the extern prototype it is not declared const? (This is an exception to the usual rule that the extern arguments should match the definition arguments?)<br>
> ><br>
> > Just so I understand, this declaration and definition:<br>
> ><br>
> > void foo(const int a);<br>
> ><br>
> > void foo(const int a) {<br>
> > }<br>
> ><br>
> > is legal, and would prevent a developer from accidentally assigning to a, but we are outlawing it. I do not<br>
> > see the rationale.<br>
> ><br>
> > Matt<br>
> ><br>
> > Thanks<br>
> ><br>
> > Barry<br>
> ><br>
> > > It is useful to have const pass-by-value parameters in function<br>
> > > definitions. Not useful in the function declarations or for the<br>
> > > caller.<br>
> > ><br>
> > > This is so that a developer does not assign to a passed-in int<br>
> > > unintentionally. Almost all C and C++ compilers accept it and they<br>
> > > error out if one does something like the code below. An exception<br>
> > > is old IRIX compilers that emit a warning on using const pass-by-value<br>
> > > and said it is meaningless to use them. I disagree.<br>
> > ><br>
> > > void f(const int n, int* j)<br>
> > > {<br>
> > > *j = n;<br>
> > > n = 0; // error<br>
> > > }<br>
> > ><br>
> > > Of course it is more useful for preventing bugs in more complex<br>
> > > functions.<br>
> > ><br>
> > > Chetan<br>
> > ><br>
> > ><br>
> ><br>
> ><br>
> ><br>
> ><br>
> > --<br>
> > What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
> > -- Norbert Wiener<br>
><br>
><br>
><br>
><br>
> --<br>
> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
> -- Norbert Wiener<br>
<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener<br>