7 ms·
I am sorry, I don't quite understand where the "abuse" comes in. Attaching function pointers to structs? I've done that in production twenty years ago (and othe
by _0ffh 2y ago
I am sorry, I don't quite understand where the "abuse" comes in. Attaching function pointers to structs? I've done that in production twenty years ago (and others have probably done it in the 70s) and I see nothing wrong with it. C gives us function pointers for a reason, and it's not to not use them... to me, at least, they're actually one of the premier features of C! (GCC's goto *ptr on the other hand, now there's some potential for getting a little bit wild...)
- uecker 2y agoI assume it is because nowadays there are so many people running around claiming you need C++ or Rust or other more complicated languages to build abstractions, that people do not understand anymore that you can do this in C just fine.
- usrnm 2y agoI don't think I've ever seen a large C codebase that wasn't using structs with methods. It isn't by any measure a secret or lost art.
- uecker 2y agoAnd yet, here we are reading about it in the news.
- userbinator 2y agoThe earliest C++ compilers compiled to C, and I believe that's still possible to do even for the latest versions of the C++ standard.
- nextaccountic 2y agoIt's always possible to compile a turing complete language into another turing complete language, so this statement doesn't carry much meaning. The interesting thing with the original C++ (then called "C with classes") compiler, Cfront, which compiled to C, was that it was an 1:1 transpiler that offered only local transformations with no global analysis (you can transform one function at time without looking at the rest of the code). The structure of the generated C code closely matched the C++ source code. This is something that's not always possible when compiling a language into another, this only happens when a language offers essentially just syntactic sugar over another, like Coffeescript and Javascript. I guess that if you compile exceptions using setjmp/longjmp and expanded all templates (I don't think you can compile templates into C macros), and also expanded method overloading and type inference, then all other features from modern C++ are only local transformations. Well maybe with the exception of couroutines from C++20 (which maybe can be compiled into setjmp/longjmp as well, if it can interact well with exceptions? But the purpose of couroutines is to compile into a state machine, which is a non local transformation) The original Cfront compiler didn't implement even exceptions (they wanted to but Wikipedia said the code was a mess [0] so it was abandoned), but that another, later C++ compiler [1] compiled into C and implemented exceptions and other things [0] https://en.wikipedia.org/wiki/Cfront https://en.wikipedia.org/wiki/Cfront [1] https://en.wikipedia.org/wiki/Comeau_C/C%2B%2B https://en.wikipedia.org/wiki/Comeau_C/C%2B%2B
- alberth 2y agoPeople sometimes use structs when a class has only public members. And I believe the STL is also implemented that way as well.
- fsckboy 2y ago>I am sorry, I don't quite understand where the "abuse" comes in. Attaching function pointers to structs? i had the same reacion, then i realized (and yes, i know the following opinion is a minority oldschool boomer opinion, no need to downvote me to hell to make sure i know) JSON itself is the abuse of C/unix, like XML before it.