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

Translating .cpp to .c

Name: Anonymous 2013-08-14 1:02

is there some automation tool that converts C++ to C code?

Name: Anonymous 2013-08-14 1:05

is there some automation tool that inserts my penis into your anus?

Name: Anonymous 2013-08-14 1:38

Name: Anonymous 2013-08-14 2:49

Its time to convert to SEPPLES, >>1.
It won't be painful, just rename your files to .cpp/.hpp.

Name: Anonymous 2013-08-14 3:58

You don't need a tool, just make a script.
1. Remove all member functions from classes to the global namespace.
2. Convert all classes to structures.
3. Use function pointers to point to the former member functions.
4. Replace all new with malloc().
5. Replace all template shit with void*.

Literally could not be any fucking simpler.

Name: Anonymous 2013-08-14 4:09

>>5
that's terrible. Use a vtable for the virtual member functions. And there's bit more, though not much. dynamic_cast. static_cast, the pattern matching component of templates. The calling of constructors and destructors. new[] and delete[]. exceptions. virtual inheritance (a bit of a bitch). and that's about it.

Name: leik dis 2013-08-14 4:31


class c {
public:
    c() {}
    ~c() {}
    int not_virtual() { return data; }
    virtual int im_virtual() { return data - 1; }
    int data;
};


can become


struct c_vtable {
    int (*im_virtual)();
};

struct c {
    struct c_vtable* vtable;
    int data; 
}

void c_constructor(struct c* this) {
}

void c_destructor(struct c* this) {
}

int c_not_virtual(struct c* this) {
    return this->data;
}

int c_im_virtual(struct c* this) {
    return this->data - 1;
}


If cinst is an instance of class c, then calling the virtual im_virtual method would look like


d->vtable.im_virtual(d);

Name: Anonymous 2013-08-14 4:34

I left out initialization of the vtable;


struct c_vtable c_vtable = { c_im_virtual };

void c_constructor(struct c* this) {
    this->vtable = &c_vtable;
}

Name: Anonymous 2013-08-14 7:07

>>3
C-C-C-Cfront.

C++ features don't directly map to C
Yes they do. (Maybe with the exception of... exceptions? I still think it can be done in C.)

Name: Anonymous 2013-08-14 7:15

>>9
#include <stdio.h>
#include <setjmp.h>

#define TRY do{ jmp_buf ex_buf__; if( !setjmp(ex_buf__) ){
#define CATCH } else {
#define ETRY } }while(0)
#define THROW longjmp(ex_buf__, 1)

TRY
{
  printf("In Try Statement\n");
  THROW;
  printf("I do not appear\n");
}
CATCH
{
  printf("Got Exception!\n");
}
ETRY;

Name: Anonymous 2013-08-14 7:42

>>9
C++ was bootstrapped as a C preprocessor.

But you'll never map a template library to C.

Name: Anonymous 2013-08-14 10:19

Name: Anonymous 2013-08-15 10:25

>>9
I still think it can be done in C.
What do you think C++ was originally implemented in?

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