Advertisement

07.11.2008 at 08:33PM PDT, ID: 23559148
[x]
Attachment Details

tangled in pointers

Asked by kayvey in C Programming Language

I could shoot myself.  I should know this.  I had this working for some reason and now I don't know
what is going on.


monsters.c:47: error: dereferencing pointer to incomplete type
monsters.c:48: error: dereferencing pointer to incomplete type

bizzare things are happening. I can break different files with different messed up tries at creating data structures

cs61c-bg@nova [60] ~/proj/01 > ls
Makefile            globals.c           monsters.c          puzzles.h
commands.c          globals.h           monsters.h          puzzles.o
commands.h          level.c             monsters.h.ta       spec/
common.h            level.h             obj/                special_gamefiles/
game*               level.h.ta          patch.c             testworld.lvl
game.c              level_table         patch.h             util.c
game.h              main.c              puzzles.c           util.h
cs61c-bg@nova [61] ~/proj/01 >

sometimes I break commands, sometimes monsters.   commands has the room structure


/* We need this typedef because exit_t contains a room_t*,
 * but the compiler hasn't seen room_t yet. This works
 * because pointers are all the same size, and the
 * compiler doesn't need to know what *kind* of pointer a
 * room_t* is. */
typedef struct room room_t;

// a struct representing an exit
typedef struct {
    room_t *dest;
    bool locked;
} exit_t;


// a struct containing all the information which represents a room
struct room {
    int room_id;
    char *description;
    mob_t *mob;
    exit_t exits[NUM_DIRECTIONS];
    puzzle_t puzzle;
};


for the life of me I have been confused about the mob_t thing.  They had it typedef void * mob_t
and I made the code work by just casting mob_t to mob_iterator_t, and now I can't get it back.
This is making no sense.



    1  #ifndef MONSTERS_H
     2  #define MONSTERS_H
     3
     4  // sets monster rarity, so that on entering any room,
     5  // a monster is generated with probability 1 / MONSTER_RARITY.
     6  #define MONSTER_RARITY 5
     7
     8  // an instance of this struct defines a monster and provides all its numerical attributes.
     9  // the monsters[] array in monsters.c lists instances of this struct that are used as templates
    10  // for creating monsters.
    11
    12
    13  typedef struct {
    14      char *name;
    15      char *attack;       // attack name, e.g. "bite"
    16      unsigned level;     // a monster can only be spawned when its level <= the player's level
    17      int hp;             // hp stands for "hit points" or "health points"
    18      unsigned damage;    // damage done when attacking the player
    19      unsigned exp;       // experience points provided when the player kills the monster
    20      unsigned frequency; // a value that reflects the relative frequency with which a monster is spawned
    21      char *description;  // a description of the beast
    22  } monster_t;
    23
    24
    25  /*** DEFINE THE mob_t TYPE HERE ***/
    26  /*** use a typedef and any struct definitions you need ***/
    27  typedef struct mob_iterator mob_iterator_t;
    28  /*** DEFINE THE mob_iterator_ty TYPE HERE ***/
    29  typedef struct {
    30          /*** YOUR MEMBER VARIBLES HERE ***/
    31      monster_t **monster_list; /* simply a list of monster pointers */
    32      int monster_count;   /* keep track of the count to make counting them easy */
    33      int this_monster;    /* index to the array of monsters will work for getting the next one */
    34      mob_iterator_t * next; /**/
    35  } mob_iterator;
    36
    37
    38  typedef void * mob_t;
    39


Start Free Trial
[+][-]07.11.2008 at 08:39PM PDT, ID: 21987542

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.11.2008 at 09:18PM PDT, ID: 21987670

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C Programming Language
Sign Up Now!
Solution Provided By: josgood
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.11.2008 at 10:26PM PDT, ID: 21987817

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.11.2008 at 11:06PM PDT, ID: 21987866

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628