Back to the main topic, using structures properly will result in the best code you can produce for anything not trivially small. Practically every CPU I know of is specifically optimized to make addressing elements in the C structure as efficient as possible.
In your case, if there are a lot of functions to which you pass the pointer to the structure, then if you take care of the organization it means that they really do have to operate on the structure. But if you have a lot of arguments to any function, you probably need some even bigger structure and pass that around.
/* okay */
struct monster {
unsigned id;
int x, y, hp;
/* etc. */
};
/* better */
struct point { int x, y; };
struct monster {
unsigned id;
struct point pos;
int hp;
};
This also allows a form of inheritance. For example if you have struct bad_monster {
struct monster base;
int badness; /* your imagination is the limit. */
};
/* this is safe */
struct bad_monster bad;
struct monster *some_monster = (struct monster *)&bad; /* equivalently &bad.base */
some_function_expecting_a_monster(some_monster);
/* only safe if it was originally a struct bad_monster */
struct bad_monster *bad_ptr = (struct bad_monster *)some_monster;
Those are the ways I tend to break up structs when writing C code. Basically by using lots of composition.And now you've reinvented (the basic premise of) OOP!
http://en.wikipedia.org/wiki/Object-oriented_programming#Fun...
Let's stay on topic, talking about C. We'll avoid philosophy and hype and will keep talking about the work being done in C.