News for hackers. Stuff that matters.
Re:OOP in C by AlbertoGP on Sunday January 08, 2023 @08:34AM (#34298976)
I made a pre-processor [1] to add similar features to C, and after reading your comment I’m thinking that it would be simple to add a setting/#pragma to do these transformations:

    list->init(); → list->init(list);
    list.init();  → list.init(&list);
[1] https://sentido-labs.com/en/library/cedro/202106171400/#back...

I normally avoid the function pointer overhead, which can be done with _Generic:

    #define append(VEC, START, END) _Generic((VEC), \
      Vec_float*: append_Vec_float, \
      Vec_str*: append_Vec_str, \
      Vec_cstr*: append_Vec_cstr \
      )(VEC, START, END)
https://sentido-labs.com/en/library/cedro/202106171400/#loop...

But list->init(list) might be a simpler solution for most cases, and compatible with C89/C99.

Re:OOP in C by AlbertoGP on Sunday January 08, 2023 @11:20AM (#34300357)
I’ve built it for now in a separate branch called “self”:

    git clone -b self https://github.com/Sentido-Labs/cedro.git
    cd cedro
    make bin/cedro # Just “make” will build cedrocc etc.
    bin/cedro - <<'    EOF' # Mind the indentation.
    #pragma Cedro 1.0 self
    list->init();
    list.init();
    list->append(123);
    list.append(123);
    EOF
The “self” flag after “#pragma Cedro 1.0” activates the “self” macro, because it should not be done by default.

Result:

    list->init(list);
    list.init(&list);
    list->append(list, 123);
    list.append(&list, 123);
I’ll try it out for a few days and if it works well in practice I’ll document it and merge it into master.
Re:OOP in C by Koshkin on Sunday January 08, 2023 @12:40PM (#34301156)
> I made a pre-processor

You followed the path of C++.

Re:OOP in C by AlbertoGP on Sunday January 08, 2023 @01:04PM (#34301407)
> You followed the path of C++.

To some extent yes, I know about cfront.

This is just another iteration on that old idea.

Re:OOP in C by KerrAvon on Sunday January 08, 2023 @03:22PM (#34302681)
Sure; you’re basically implementing The prehistoric version of C++, called “C with Classes.” If you’re unaware, see Stroustrup’s Design and Evolution of C++ book.

Which is fine! Should be interesting.