void wierdWhile(int count) { int n = (count-1)/8 + 1; switch(count %8) { case 0: do{ case 1: foo(); case 2: foo(); case 3: foo(); case 4: foo(); case 5: foo(); case 6: foo(); case 7: foo(); }while(--n > 0); } } void foo() { printf("Foo here, i'm giving you the bar.\n"); }Yes. It compiles (ANSI C).
Yes. It works(if my memory is not screwing up).
What does it do? A very simple thing that in embedded coding might be very useful. The jump from while is not such a low cost operation, so to save while rolls this little helper is used. It was presented to me while applying to one company. The recrutation process didn't go as planned since this code blew my mind a bit.
Hope It'll help you in some way!
No comments:
Post a Comment