Interesting thought....

Started by
14 comments, last by LessBread 18 years, 6 months ago
Hello. I am having this thought... Can i combine a bunch of functions in a sort of an object, i mean under "C", and pure "C". Basically, translate this to "C":

class test {
public:
    test();
    void tester(int a);
private:
    int s;
};

Thanks in advance!
This world is ruled by big furry CATS!! :)Meow! :)
Advertisement
Function Pointers. Take a look at the Quake 3 source. Its done a lot of times, obviously you wont have inheritance and such, but you can cheat.

struct test{  void (*test)();  void (*tester)(int a);  int s;}


Also, my syntax may be wrong, I don't frequently use function pointers.
Adventures of a Pro & Hobby Games Programmer - http://neilo-gd.blogspot.com/Twitter - http://twitter.com/neilogd
The way to do that is to have a series of global functions which act on a handle to the instance (either a pointer to a struct, or an opaque value).
Quote:Original post by Catafriggm
The way to do that is to have a series of global functions which act on a handle to the instance (either a pointer to a struct, or an opaque value).


Or that...
Adventures of a Pro & Hobby Games Programmer - http://neilo-gd.blogspot.com/Twitter - http://twitter.com/neilogd
Quote:Original post by Catafriggm
The way to do that is to have a series of global functions which act on a handle to the instance (either a pointer to a struct, or an opaque value).


Can you please explain a bit more...

This world is ruled by big furry CATS!! :)Meow! :)
Quote:Original post by Ancient Spirit
Quote:Original post by Catafriggm
The way to do that is to have a series of global functions which act on a handle to the instance (either a pointer to a struct, or an opaque value).


Can you please explain a bit more...


struct test{  int s;}void test_test(test& object){  s = 0;  return;}void test_tester(test& object, int a){  s = a; // ?  return;}
Adventures of a Pro & Hobby Games Programmer - http://neilo-gd.blogspot.com/Twitter - http://twitter.com/neilogd
i dont think u can use the "&" in "C"
This world is ruled by big furry CATS!! :)Meow! :)
Quote:Original post by Ancient Spirit
i dont think u can use the "&" in "C"


picky picky people, this is what I get for being a pure C++ programmer

struct test{  int s;};void test_test(test* object){  object->s = 0;  return;}void test_tester(test* object, int a){  object->s = a; // ?  return;}


And I fixed a bug aswell. Now fixed the real bug.

[Edited by - Richy2k on October 9, 2005 7:17:13 PM]
Adventures of a Pro & Hobby Games Programmer - http://neilo-gd.blogspot.com/Twitter - http://twitter.com/neilogd
No, you can't, but you can replace it by a pointer.

[edit] Fixed at time of writing.
[edit2] And don't forget to actually use the pointer... ->
void test_tester(test* object, int a){  object->s = a;  return;}



jfl.
Here are a couple of links that might help.

Object-Oriented C: Creating Foundation Classes Part 1
Object Oriented Programming in C
Object Oriented Programming in C

Here's a complete book on the subject: Object-Oriented Programming With ANSI-C (pdf)

If you want to get an idea of how vtables are constructed, if you have access to a Windows based compiler, open the iunknown.h in a text editor and examine what it does with structures, forward references, and function pointers. You might also have to search for macro definitions in other headers.


"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man

This topic is closed to new replies.

Advertisement