Skip to content

Commit 05b4ed6

Browse files
committed
cocci: simplify "if (++u > 1)" to "if (u++)"
It is more common to use post-increment than pre-increment when the side effect is the primary thing we want in our code and in C in general (unlike C++). Initializing a variable to 0, incrementing it every time we do something, and checking if we have already done that thing to guard the code to do that thing, is easier to understand when written if (u++) ; /* we've done that! */ else do_it(); /* just once. */ but if you try to use pre-increment, you end up with a less natural looking if (++u > 1) Signed-off-by: Junio C Hamano <[email protected]>
1 parent cae598d commit 05b4ed6

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

contrib/coccinelle/preincr.cocci

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@ preincrement @
2+
identifier i;
3+
@@
4+
- ++i > 1
5+
+ i++

0 commit comments

Comments
 (0)