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:
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.
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.
I normally avoid the function pointer overhead, which can be done with _Generic:
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.