Ticket #1951 (closed enhancement: wontfix)
Simplify
| Reported by: | pavlinux | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | |
| Component: | mc-core | Version: | master |
| Keywords: | Cc: | ||
| Blocked By: | Blocking: | ||
| Branch state: | no branch | Votes for changeset: |
Description (last modified by styx) (diff)
(x + 1) * 2 = ++x << 1
Attachments
Change History
comment:3 Changed 16 years ago by pavlinux
May be this
#include <stdio.h>
#define LIMIT 0x20
int main() {
int sp = 0;
int dp = 0;
int i = 0;
while ( (2*dp) <= LIMIT ) {
printf("%ld\n", 2*dp);
dp++;
}
while ( sp <= LIMIT ) {
printf("%ld\n", sp);
sp = 2 * ++i;
}
return 0;
}
comment:4 Changed 16 years ago by styx
- Description modified (diff)
In you code variables are named not well. 'i' is now equal to 'backspaces' an 'backspaces' became to be equal to 2*old_backspaces. Yes, the result is the same, but the logic is changed.
Note: See
TracTickets for help on using
tickets.

Code for test
#include <stdio.h> int main(void) { int sp = 0; int dp = 0; while ( sp < 0xFF /* just limit */ ) { sp = (++sp << 1); dp = 2 * ( dp + 1 ); printf("%d = %d\n", sp, dp); } return 0; }