Difference between revisions of "Talk:Writing Modules In C"
Grazzhoppa (talk | contribs) (Why do you need to declare a Link* named ink when using FOR_EACH_PLAYER macro?) |
Mine GO BOOM (talk | contribs) |
||
Line 5: | Line 5: | ||
quote from article: | quote from article: | ||
"''There is an ASSS macro, FOR_EACH_PLAYER, that will help us loop through every player. To use this macro we need: a Player* '''and a Link* named link.'''''" | "''There is an ASSS macro, FOR_EACH_PLAYER, that will help us loop through every player. To use this macro we need: a Player* '''and a Link* named link.'''''" | ||
+ | |||
+ | [[User:Mine GO BOOM|Mine GO BOOM]] 15:56, Oct 3, 2006 (PDT): In player.h, the macro FOR_EACH_PLAYER is defined as the following. The for line assumes a '''Link*''' variable named '''link''' for it to work correctly. Under C++, you could initalize the '''link''' variable in the '''for''' loop but you cannot in C. A slightly better method would have the '''Link*''' variable name be include in the macro's definition instead of assuming a variable named '''link'''. | ||
+ | <pre>#define FOR_EACH_PLAYER(p) \ | ||
+ | for ( \ | ||
+ | link = LLGetHead(&pd->playerlist); \ | ||
+ | link && ((p = link->data, link = link->next) || 1); )</pre> |
Revision as of 18:56, 3 October 2006
The example given for how to use the FOR_EACH_PLAYER macro doesn't show why you need a Link pointer named link!
The example just declares the variable, without initializing it to any value, and doesn't do anything with the Link pointer after that.
quote from article: "There is an ASSS macro, FOR_EACH_PLAYER, that will help us loop through every player. To use this macro we need: a Player* and a Link* named link."
Mine GO BOOM 15:56, Oct 3, 2006 (PDT): In player.h, the macro FOR_EACH_PLAYER is defined as the following. The for line assumes a Link* variable named link for it to work correctly. Under C++, you could initalize the link variable in the for loop but you cannot in C. A slightly better method would have the Link* variable name be include in the macro's definition instead of assuming a variable named link.
#define FOR_EACH_PLAYER(p) \ for ( \ link = LLGetHead(&pd->playerlist); \ link && ((p = link->data, link = link->next) || 1); )