Re: Function Pointers?

From: Joachim Pileborg (pilen@TRELLEBORG.MAIL.TELIA.COM)
Date: 02/18/98


At 17-Feb-98, Jon Barrett wrote:

Add the following line somewhere near the top of spells.h:
typedef void (*spell_function)(int, struct char_data *, struct char_data *,
struct obj_data *, int);

> struct spell_info_type {
>    byte min_position;   /* Position for caster   */
>    int mana_min;        /* Min amount of mana used by a spell (highest lev)
*/
>    int mana_max;        /* Max amount of mana used by a spell (lowest lev)
*/
>    int mana_change;     /* Change in mana used by spell from lev to lev */
>    bool is_innate[NUM_RACES];
>    int min_level[NUM_CLASSES];
>    byte violent;
>    int targets;         /* See below for use with TAR_XXX  */
>    void (*spell_function)
>         (int level, struct char_data *ch, struct char_data *victim, struct
> obj_data *obj, int spellnum);
> };

Change the spell_function definition to the following:
   spell_fun spell_function;

> void spello(int spl, int max_mana, int min_mana, int mana_change, int
> minpos,
>                  int targets, int violent, void (*func))

Change the "void (*func)" thing to: spell_fun func

> {
>   int i;

>   for (i = 0; i < NUM_CLASSES; i++)
>     spell_info[spl].min_level[i] = LVL_IMMORT;
>   spell_info[spl].mana_max = max_mana;
>   spell_info[spl].mana_min = min_mana;
>   spell_info[spl].mana_change = mana_change;
>   spell_info[spl].min_position = minpos;
>   spell_info[spl].targets = targets;
>   spell_info[spl].violent = violent;
>   *spell_info[spl].spell_function = func;  //ERROR points here
> }

And finaly change the last assignment to:
   spell_info[spl].spell_function = func;

This should work (it is untested though).

/ Joachim
--

The Arrow!
Joachim Pileborg     Phone   : +46-(0)410-40915
C.B. Friisgatan 1    Cellular: 0705-654429
23142 TRELLEBORG     Email   : pilen@trelleborg.mail.telia.com
Sweden               WWW     : http://w1.410.telia.com/~u41003102


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST