lkj
LV6 Super Member (Next: 500)
    
Online
Gender: 
Last Login: Today at 13:52:01
Date Registered: 07 September, 2011, 20:05:25
Posts: 364
Topic starter
Total Post Ratings: +40
|
 |
« on: 07 September, 2011, 20:28:05 » |
0
|
I have a problem with the following code: 1 2 3
| for(w = 0, w < levelheader->number_of_eggs, ++w){ //do something } |
Where levelheader is a pointer to a struct: 1 2 3 4 5
| 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 
|
|
|
|
|
Logged
|
My Nspire Ndless C projects:
|
|
|
calc84maniac
Epic z80 roflpwner
Coder Of Tomorrow
LV11 Super Veteran (Next: 3000)
Offline
Gender: 
Last Login: Today at 06:30:47
Date Registered: 28 August, 2008, 05:09:05
Location: Right behind you.
Posts: 2738
Total Post Ratings: +376
|
 |
« Reply #1 on: 07 September, 2011, 20:59:50 » |
0
|
In a for loop, you need to separate the statements with semicolons, not commas.
|
|
|
|
|
Logged
|
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman
|
|
|
lkj
LV6 Super Member (Next: 500)
    
Online
Gender: 
Last Login: Today at 13:52:01
Date Registered: 07 September, 2011, 20:05:25
Posts: 364
Topic starter
Total Post Ratings: +40
|
 |
« Reply #2 on: 07 September, 2011, 21:06:20 » |
0
|
Thank you Sometimes I make really silly mistakes...
|
|
|
|
|
Logged
|
My Nspire Ndless C projects:
|
|
|
|
t0xic_kitt3n
|
 |
« Reply #3 on: 07 September, 2011, 22:42:16 » |
0
|
You're not alone, I kept on doing that for a while too 
|
|
|
|
|
Logged
|
██████ ██ ██ ███████ ████ ██ ██ ██ ███████ █ ██ █ ██ ██ ██ █ ██ ██ ████ ███ ███ ██ █ ██ ██ ██ ██ ██ ██ ██ ██ ███████ ██ ██ ██ ██ ██ █ ██ ██ ██ ███████ ██ █ ██ ██████ █████ ██ ██ ██ ██ █ ██ █████ ██ ██ ██ ██ █ ██ ███ ██████ ██ ██ ██ █ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ █ ██ ██ ██ ██ ██ ██ ██ █ ████ ██ ██ ███████ █████ ██ ██ ██ ██ ███████
|
|
|
|
Munchor
|
 |
« Reply #4 on: 07 September, 2011, 22:55:00 » |
0
|
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/)
|
|
|
|
« Last Edit: 07 September, 2011, 22:55:29 by ephan »
|
Logged
|
|
|
|
|
Ashbad
Guest
|
 |
« Reply #5 on: 07 September, 2011, 23:01:59 » |
0
|
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.
|
|
|
|
|
Logged
|
|
|
|
Tribal
Anti-Riot Squad
LV5 Advanced (Next: 300)
Offline
Gender: 
Last Login: 12 May, 2013, 02:02:17
Date Registered: 02 September, 2008, 22:38:51
Location: $0001
Posts: 237
Total Post Ratings: +13
|
 |
« Reply #6 on: 08 September, 2011, 06:32:30 » |
0
|
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.
|
|
|
|
|
Logged
|
|
|
|
|
calcdude84se
|
 |
« Reply #7 on: 08 September, 2011, 06:47:25 » |
0
|
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.
|
|
|
|
|
Logged
|
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster." -Adam Osborne Bug me about PartesOS. I might just need reminding.
|
|
|
|