this one time i went to these guys and i wall all "hey guys check out my c code" and they were all "dude your code sucks" and i was all "no dude nothing is wrong with my code" and then the guy was all "you used a break statement in nested while loops" so i said to him i says "dude thats totally legit" and hes all "dude your noob programmer if you compile that in a very specific way then there is a chance that the code wont work" so i told him right to his face that he is a faggot and wrong because my code worked and i didn't care if it wouldn't work compiled that way because maybe i won't compile it that way
This is one reason I will never be a great C programmer. There's decades of idioms and gotchas you have to know about.
Name:
Anonymous2011-12-25 2:47
#define Hello int main
#define prog (){
#define I int i;
#define just for(i=0;i<5;++i)
#define ate {
#define toast printf("%s", Best Story Ever");
#define The }
#define End }
#define foreach(a, f) \
do { \
int i; \
for (i = 0; i < sizeof (a) / sizeof *(a); i++) \
(f)((a)[i]); \
} while (0)
int main(void) {
foreach(((char *[]){ "Best Story Ever"
, "Best Story Ever"
, "Best Story Ever"
, "Best Story Ever"
, "Best Story Ever"
}), puts);
return EXIT_SUCCESS;
}
>>22
So write a better design. while (!endgame)
{
while (code==CODEBLUE)
{
// do stuff
if (gameaction==PLAYERQUIT)
{
gameaction=CODERED;
endgame = true;
}
}
}
Name:
Anonymous2011-12-25 23:20
int i = 0;
while (1)
{
i += 2
if (i == 8)
{
break;
}
}
I don't see anything wrong with this in terms of efficiency.
But the while loop has to check that 1 == 1 each time it runs through the loop, whereas the for loop doesn't. So the while loop does 13 operations, whereas the for loop only does 8 operations.
A problem with the for loop is that the compiler will optimise the loop away, because it does nothing.
Name:
Anonymous2011-12-25 23:53
>>27 But the while loop has to check that 1 == 1 each time it runs through the loop
No it doesn't it's a constant expression.
A problem with the for loop is that the compiler will optimise the loop away, because it does nothing.
It alters the value of i.
It's part of the loop counter though. The compiler is smart enough (or if you actually need the loop to delay, then it's stupid enough) to actually optimise it away.
Name:
Anonymous2011-12-26 0:12
>>31
no fake, but when you only use one compiler and not adding to some open source project let alone a private one they don't care.
>>27 1==1
no it doesn't, that would have to be the stupidest compiler ever to even assemble to that.
As you can see with O3 the compiler is smart enough to optimize both loops to not even do a loop or any jumps and just does 4 prints and then in the main method it just does 8 prints instead of even using call on those two methods.
We did some microprocessor control stuff. By setting the clock multiplier to a certain value, you create a paced loop where the pacer counts to a certain number, which creates a time delay based on what the multiplier sets the clock to. If the compiler optimises the loop, wouldn't it modify the time delay to, say, make an LED flash on and off every 500ms?