Talk:Writing Modules In C

From ASSS Wiki
Revision as of 18:56, 3 October 2006 by Mine GO BOOM (talk | contribs)
Jump to: navigation, search

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); )