Source-Changes-D archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: xsrc/external/mit/libpciaccess/dist/src



On Sun, Nov 04, 2012 at 02:56:32AM -0800, Matt Thomas wrote:
> 
> On Nov 4, 2012, at 2:26 AM, David Laight wrote:
> 
> > Personally I almost never mark variables 'const', the only I initialise
> > in their declarations (at the top of a function) are probably almost
> > always never chaned (well maybe execpt default error values).
> 
> Personally, I always mark variable as const if I don't expect its value to 
> change since that documents that expectation.  This is especially true for 
> pointers:
> 
>       const struct foo_softc * const sc = ifp->if_softc;
> 
> Once nice side effect is that it catches errors like:
> 
>       if (sc = NULL) {
>       }

I have taken to making variables const for the same reason.

Sometimes, when dealing with hairy code such as 30 year-old code in the
networking stack, I mark a variable const so that the compiler will
gripe if the variable is re-assigned.  It's easier then to understand
some code and to refactor it.

Dave

-- 
David Young
dyoung%pobox.com@localhost    Urbana, IL    (217) 721-9981


Home | Main Index | Thread Index | Old Index