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

Why is C++...

Name: Anonymous 2011-12-07 12:06

...so bad? Why does it have such a bad reputation?

I'm an experienced C++ programmer and, while the language has warts, I can't understand the reason for the enormous amount of criticism against the language.

I'd like to hear the honest opinions of /prog/rammers in this regard.

Name: Anonymous 2011-12-18 3:20

>>247

here ya go:


struct refc {
  int count;
  void (*destructor)(void*);
};

#define INC_REF(p) if(p) ((struct refc*)(p))->count++
#define DEC_REF(p) if((p) && (--(((struct refc*)(p))->count)) == 0); ((struct ref*)(p))->destructor(p)

struct list {
  struct refc refc;
  void* car;
  struct list* cdr;
};

void destroy_list(struct list* lis);

void* cons(void* car, struct list* cdr) {
  struct list* a = malloc(sizeof(struct list));
  assert(a);
  a->refc.count = 0;
  a->refc.destructor = (void(*)(void*))destroy_cons;
  a->car = car;
  INC_REF(car);
  a->cdr = cdr;
  INC_REF(cdr);
  return (void*)a;
}

void destroy_list(struct list* lis) {
  DEC_REF(lis->car);
  DEC_REF(lis->cdr);
}

void* remove_duplicates(void* xs, int(*eq)(void*,void*)) { // removes the consecutive duplicates in a list
  if (xs == NULL || xs->cdr == NULL) return xs;
  if(eq(xs->car, xs->cdr->car)) return remove_duplicates(xs->cdr); // tail recursion
  return cons(cs->car, remove-duplicates(xs->cdr)); // no tail recursion
}

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