News for hackers. Stuff that matters.
Re:Generics in C without void* or macros – enabled by psychec by wvenable on Monday September 09, 2019 @11:44AM (#20919205)
One of the reasons C++ is so complicated is that you don't pay for the features that you don't use. If you wanted generics in C, you can easily use C++ without any of those other features (baggage, if you will) and not pay for it.

Heck, you could define a few macros and make it impossible to use any baggage features you don't like.

I've used C++ in a pretty tight embedded environment and it was great.

Re:Generics in C without void* or macros – enabled by psychec by Crinus on Monday September 09, 2019 @11:51AM (#20919265)
You may not pay for them (generally) in terms of execution time, but you pay for them in terms of compilation time and language complexity.
Re:Generics in C without void* or macros – enabled by psychec by wvenable on Monday September 09, 2019 @12:00PM (#20919347)
If I don't use them then language complexity doesn't matter. Compilation times might be a factor assuming that turning them off doesn't also decrease that (which it might).
Re:Generics in C without void* or macros – enabled by psychec by bsder on Monday September 09, 2019 @04:19PM (#20922000)
> I've used C++ in a pretty tight embedded environment and it was great.

I'd love to hear some details. I'm always looking for C++ stories that didn't end in disaster and what the people did that worked.

Re:Generics in C without void* or macros – enabled by psychec by com2kid on Monday September 09, 2019 @07:46PM (#20923754)
I've done similar. The Microsoft Band UI was written in C++. No templates or other advanced features, compiler was stuck on 2003 standard. We had templates but used the trick of implementing them in a .cpp file and declaring all the instanciations of them we'd ever use at the bottom of the same file. Had to write our own to guarantee 0 allocs.

It is quite do-able. Lots of static declarations, basically write C with classes. V-tables ended up being non-trivial in size, but what can you do, GUIs and all that. Possibly the best (only?) good use of inheritance hierarchies.

256KB memory, the UI only had 60KB or so available for it IIRC. We also had a scratch pad available over a super slow bus of a couple megs, but it couldn't be used too much or we'd drop frames and we loved our 30fps v-sync'd performance.

Re:Generics in C without void* or macros – enabled by psychec by dragontamer on Monday September 09, 2019 @06:54PM (#20923388)
Pretty much any CUDA programmer can talk about how they got 1024 threads working on 64kB "shared memory" with their C++ compiler. That "shared memory" region is exceptionally fast, so its a good idea to hyper-optimize your memory accesses to use that region.

There are some very interesting constraints in GPU-programming. Fitting C++ classes and even some data-structures in the "shared memory" region is pretty nifty.