Omnimaga
Calculator Community => TI Calculators => Calculator C => Topic started by: lkj on September 07, 2011, 02:28:05 pm
-
I have a problem with the following code:
for(w = 0, w < levelheader->number_of_eggs, ++w){
//do something
}
Where levelheader is a pointer to a struct:
typedef struct LEVElHEADER{
//...
uint16_t number_of_eggs;
//...
}levelheader_t;
When I try to compile it, I get these errors :
test.c:7:18: warning: value computed is not used
test.c:7:54: error: expected ';' before ')' token
I just can't find the problem ???
-
In a for loop, you need to separate the statements with semicolons, not commas.
-
Thank you
Sometimes I make really silly mistakes...
-
You're not alone, I kept on doing that for a while too :P
-
By the way, you used "++w", shouldn't it be "w++"? I've seen both being used but I can't understand the different.
EDIT: Oh wait, I got it (http://www.gamedev.net/topic/337133-i-vs-i/ (http://www.gamedev.net/topic/337133-i-vs-i/))
-
By the way, you used "++w", shouldn't it be "w++"? I've seen both being used but I can't understand the different.
very different. they both increment, but ++w applies before the value is taken into account, w++ applies after the whole line has been run through.
-
By the way, you used "++w", shouldn't it be "w++"? I've seen both being used but I can't understand the different.
EDIT: Oh wait, I got it (http://www.gamedev.net/topic/337133-i-vs-i/ (http://www.gamedev.net/topic/337133-i-vs-i/))
Just as a side note, it is more efficient to do ++w. So if you don't need the value of w before it's incremented, then use ++w instead.
-
Just as a side note, it is more efficient to do ++w. So if you don't need the value of w before it's incremented, then use ++w instead.
Except any good compiler will compile "w++" to the same as "++w" if the result isn't used. (I know the discussion ephan linked says that this might not be the case sometimes, but that's for C++) If precedent helps, I've always seen it written postfix for the loop increment.