On Aug 30, 2013, at 9:48 PM, Simon Horman <ho...@verge.net.au> wrote:

> On Fri, Aug 30, 2013 at 01:40:16PM -0700, Jarno Rajahalme wrote:
>> +        LIST_FOR_EACH(bucket, list_node, &gm->buckets) {
>> +            ++n_buckets;
> 
> Any reason you favour a pre-increment over a post-increment.
> I realise it makes no difference to the logic here but I am curious.
> 

I guess it is a habit that stuck after writing some C++ iterators. With more 
complex types post-increment is costly, as it requires a copy of the original 
value to be made before the increment, so that the value before the increment 
can be returned as the value of the operation. Pre-increment is semantically 
simpler, as it returns the value after the increment and no copies are needed. 
I guess compilers can easily eliminate unneeded copies in most cases, 
especially whenever the iterator code gets inlined.

Besides, I just spent some time last week debugging a post-increment bug I made 
by assigning the value to another variable without being mindful of the fact 
that the statement that assigned from was a POST-increment, while I was 
thinking to having had assigned the incremented value.

  Jarno

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to