[webkit-dev] Using C++ constant pointers (type_name * const) in WebKit

2011-11-28 Thread David Kilzer
In a discussion on Bug 71921, Antti, Darin Adler and I started a discussion 
about using C++ constant pointers in WebKit.  Does the WebKit community have a 
consensus opinion on the matter?

* Pros
  - Documents use of variable.
  - Prevents misuse of variable in a later patch (by a different author) 
through enforcement of pointer const-ness.
  - May help compiler optimize code.  (We weren't sure whether modern compilers 
do this on their own or not.)

* Cons
  - Darin Adler doesn't ever recall fixing a bug in WebKit where a constant 
pointer would have helped.
  - Slightly more verbose syntax for constant pointers to a constant string 
(const char * const pointer;) or even a constant pointer to a mutable string 
(char * const pointer;).

Dave

___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev


Re: [webkit-dev] Using C++ constant pointers (type_name * const) in WebKit

2011-11-28 Thread Peter Kasting
On Mon, Nov 28, 2011 at 1:38 PM, David Kilzer ddkil...@webkit.org wrote:

 In a discussion on Bug 71921https://bugs.webkit.org/show_bug.cgi?id=71921,
 Antti, Darin Adler and I started a discussion about using C++ constant
 pointers in WebKit.  Does the WebKit community have a consensus opinion on
 the matter?


It seems like the const in T * const idName is equally useful (or
useless) to the const in const T idName.  Both are saying that |idName|
(as opposed to what it points to, in the first case) is constant.  In both
cases people are rarely in that habit of using const, especially when
|idName| is a local.  The same pros and cons seem to apply to both.
 Therefore I would suggest that if we want to make a rule, we make it apply
to both cases.

I personally like using const as much as possible (without overstepping
logical constness limits), but I also suspect my view is the minority.

PK
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev


Re: [webkit-dev] Using C++ constant pointers (type_name * const) in WebKit

2011-11-28 Thread Ryosuke Niwa
On Mon, Nov 28, 2011 at 1:38 PM, David Kilzer ddkil...@webkit.org wrote:

 In a discussion on Bug 71921https://bugs.webkit.org/show_bug.cgi?id=71921,
 Antti, Darin Adler and I started a discussion about using C++ constant
 pointers in WebKit.  Does the WebKit community have a consensus opinion on
 the matter?

 * Pros
   - Documents use of variable.
   - Prevents misuse of variable in a later patch (by a different author)
 through enforcement of pointer const-ness.
   - May help compiler optimize code.  (We weren't sure whether modern
 compilers do this on their own or not.)


Don't think so. As far as I know, C++ compilers ignore const for the
purpose of code optimization because we can always re-cast it to non-const
variable. On the other hand, modern optimizing compilers might do SSA-based
constanthttp://en.wikipedia.org/wiki/Sparse_conditional_constant_propagation
 propagation http://gcc.gnu.org/news/ssa-ccp.html regardless of constness
of a variable.

* Cons
   - Darin Adler doesn't ever recall fixing a bug in WebKit where a
 constant pointer would have helped.
   - Slightly more verbose syntax for constant pointers to a constant
 string (const char * const pointer;) or even a constant pointer to a
 mutable string (char * const pointer;).


I'd argue against using constant pointers simply because I don't think the
existing WebKit code uses it, and I don't see much benefit in comparison to
pointers or references to const objects.

- Ryosuke
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev