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

C vs. C++

Name: Anonymous 2006-02-06 12:06

So, I've decided to go ahead and teach myself Game Programming. I picked up a book that seems pretty good for the task (Thompson's "Beginning Game Programming") that deals with the creation of 2D and 3D games using C and DirectX. Now, that's all well and good, but I've never specifically dealt with C before: only C++.

C++ I've learned in several college courses (I'm a Computer Science major), and have completed all the classes offered. These covered the range from Hello World to manually creating Binary Search trees (not using any built-in libraries to do the job for me). I'm fairly comfortable with the language, though nothing I've yet created in C++ used a GUI.

I'm aware that C is sort of a precursor to C++, with more limited capabilities, and much of the syntax is the same. My question for you all is how hard would it be to pick up C having only dealt with its more advanced relative? Is there anything I should know? Any good online resources I should check? (preferrably free)

Thanks for any help you can provide.

Name: Anonymous 2010-02-24 20:51

>>1
All you need to know is this: everything they told you not to do in your C++ courses is actually the right way to do things in C.

The biggest difference you'll find is using POD structs instead of classes, and instead of methods you have plain old functions that take the struct as the first parameter. You have to implement most of the class stuff yourself, such as construction/destruction, vtables, etc. if you care to use such things.

C++:

class Foo {
  int x;

  void bar() {
    this->x = 5;
  }
}

int main() {
  Foo foo;
  foo.bar();
  return 0;
}


C:

typedef struct Foo {
  int x;
} Foo;

void FooBar(Foo* self) {
  self->x = 5;
}

int main() {
  Foo foo;
  FooBar(&foo);
  return 0;
}

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