Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

CGAME

Name: Anonymous 2011-12-29 13:41

Are any games written in pure C? Even K&R mentions that C lends itself to graphics. Why are they all written in C++ if C is so much better?

Name: Anonymous 2011-12-29 18:30

>>13

there isn't really. Just sayin, that's the hardest thing about maintaining a large c project that uses polymorphism. In the past, I've written implementations for each type:


void water_dragon_attack(animal_p self, animal_p target);
void snake_attack(animal_p self, animal_p target);
void falcon_attack(animal_p self, animal_p target);


and then I'll write a single generic function, that switches to one of the others:


void animal_attack(animal_p self, animal_p target) {
  switch(self->type) {
    case WATER_DRAGON: water_dragon_attack(self, target); break;
    case SNAKE: snake_attack(self, target); break;
    case FALCON: falcon_attack(self, target); break;
  }
}


So that way, code for the falcon can stay inside of falcon.c.
This switch statement style can do multiple dispatch too, by doing a nested switch off of target->type. The only issue as that the switch statements in the generic functions start to get really big.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List