C vs C++

Not about OpenMW? Just about Morrowind in general? Have some random babble? Kindly direct it here.
User avatar
wareya
Posts: 338
Joined: 09 May 2015, 13:07

Re: C vs C++

Post by wareya »

Depends. On certain systems, premade support libs that have the C++ runtime as a dependency can be a problem with deploying binaries. For instance, I once proposed changing OpenAL Soft to C++, in part because of Microsoft's continued horrid support for non-ancient C standards. The response I got back from other developers was an astounding "Please Don't", because if an app is distributed as a binary that uses its own packaged C++ runtime, and it links to OpenAL which pulls in the system's C++ runtime, Very Bad Things can happen.
This is a linking problem, not a language problem, and you can avoid it pretty easily if you're not using an arcane build system (oh wait, linux distros handle shared libraries in a horrifying way!). The exact same thing can happen with C projects linking glib or threading libraries. The issue with C++ libraries is that the C++ binary ABI is unstable. Any respectful C++ library will only link over the C ABI.
Chris
Posts: 1625
Joined: 04 Sep 2011, 08:33

Re: C vs C++

Post by Chris »

wareya wrote:This is a linking problem, not a language problem, and you can avoid it pretty easily if you're not using an arcane build system (oh wait, linux distros handle shared libraries in a horrifying way!).
It's not Linux that the term "DLL Hell" was coined for. Compared to Windows' "solution" with the SxS crap, shared libraries on Linux are extremely elegant.
The issue with C++ libraries is that the C++ binary ABI is unstable. Any respectful C++ library will only link over the C ABI.
Like the C++ standard library? :? If the language's own standard library can't avoid its pitfalls, what do you expect out of the language's users?

It is a language problem if the linking problem is a result of required language behavior. The lack of separation between interface and implementation, inline member functions, inheritance, RTTI, etc, ensure that the application or library will require knowledge of a class's implementation details. There's nothing linking can do to make it not rely on those details. It's the nature of the beast. The only way to avoid it is to so carefully avoid anything that requires pulling in the C++ runtime and standard libraries that you may as well just be using C.

Don't get me wrong. I love C++. And the issues it has can generally be avoided, worked around, or fixed. But sometimes a developer's desires preclude being able to do that.
Last edited by Chris on 07 May 2017, 20:47, edited 1 time in total.
User avatar
Jyby
Posts: 408
Joined: 10 Dec 2013, 04:16

Re: C vs C++

Post by Jyby »

Chris wrote:Like the C++ standard library
User avatar
Jyby
Posts: 408
Joined: 10 Dec 2013, 04:16

Re: C vs C++

Post by Jyby »

psi29a wrote:
Jyby wrote:You can turn off JIT compiling and create a binary directly. We do that for real-time / performance reasons at my company.
Yeah, it's real-time until the GC comes around and stops the whole thing... so yeah, not real-time. Not to be used in mission-critical systems.

I just find it really hard to recommend the use of Java these days except for when you have a legacy system you need to maintain/extend or your employees/peers are specialized in Java and it would be too difficult (or costly) to retrain them or let them go.

Can you recommend anything good about Java (as a language) that isn't covered by another modern language?
You can do real-time with Java, (soft or firm ok enough)... Thats done a lot. And you'd be surprised what we use it for and it is mission critical ;) (what you're probably concerned with is safety-critical systems) You design with minimum impact of the GC.
User avatar
psi29a
Posts: 5356
Joined: 29 Sep 2011, 10:13
Location: Belgium
Gitlab profile: https://gitlab.com/psi29a/
Contact:

Re: C vs C++

Post by psi29a »

I know what safety-critical systems are, that is also a problem area for Java but I was just focussing on your statement about Java being used in real-time systems. In order to be real-time you need to meet certain requirements otherwise you'll always be referred to as near-real-time.

I have to admit, I'm extremely curious on how you can guarantee real-time when the GC blocks everything until it is finished. Not knowing when the GC would run, for how long and that it won't handle any requests makes me extremely nervous (and refuse to use/deploy) in some situations.

To be fair, I have this issue with all languages that give you GC "for free". Which is why I was teasing sirherrbatka for drinking the kool-aid. ;)

I wasn't aware that some JVMs allowed native binary compilation, I know GCJ (gcc) can but I know they are a bit behind on the times.

I honestly do not know why you would build new software/systems with Java except that it would cost too much to retrain existing developers or fire them. It might be a question of costs since there a lot of Java developers out there.
User avatar
AnyOldName3
Posts: 2668
Joined: 26 Nov 2015, 03:25

Re: C vs C++

Post by AnyOldName3 »

Not all Java can be compiled to native code, as features are supported like reading in arbitrary bytecode at runtime. Even when using tools which support every sensible Java feature, typically they're very behind in terms of what version of Java they support.
User avatar
raevol
Posts: 3093
Joined: 07 Aug 2011, 01:12
Location: Caldera

Re: C vs C++

Post by raevol »

I think my big takeaway from this is, given that this turned into a programming language war instead of a discussion of programming techniques, very few people actually understand the difference between C and C++. Now I don't feel so bad for my ignorance before!
User avatar
sirherrbatka
Posts: 2159
Joined: 07 Aug 2011, 17:21

Re: C vs C++

Post by sirherrbatka »

I think you are greatly underestimating the difficulty of designing a programming language so largely used as C++, I strongly suggest you to start following the standard committee. Here.
So next time I will critize airplane crashing you will tell me that I underestimate the difficulty of airplane design? Come on!

There is not excuse here other than: C++ has everything that Stroustrup heared about back in the 80s. It is a mess. As I said before there is no reason to use C over C++ (because mess can be avoided) but It does not make C++ a well designed language. Not at all. It is certainly usable, and solves few problems here and there so it is worth knowing
User avatar
Jyby
Posts: 408
Joined: 10 Dec 2013, 04:16

Re: C vs C++

Post by Jyby »

psi29a wrote:I know what safety-critical systems are, that is also a problem area for Java but I was just focussing on your statement about Java being used in real-time systems. In order to be real-time you need to meet certain requirements otherwise you'll always be referred to as near-real-time.
I mean you can read about these things if you want, heres what my company uses: ftp://public.dhe.ibm.com/software/webse ... nux_30.pdf

These are problems for Java, but lots of thought have been put into tuning and control feedback in terms of scheduling.

You can also look into Java for embedded devices and application environments.
User avatar
wareya
Posts: 338
Joined: 09 May 2015, 13:07

Re: C vs C++

Post by wareya »

Chris wrote:
wareya wrote:This is a linking problem, not a language problem, and you can avoid it pretty easily if you're not using an arcane build system (oh wait, linux distros handle shared libraries in a horrifying way!).
It's not Linux that the term "DLL Hell" was coined for. Compared to Windows' "solution" with the SxS crap, shared libraries on Linux are extremely elegant.
On windows, you can statically link libraries like libstdc++ or openal to avoid problems like this and nobody will bat an eye. Linux package maintainers would die before doing so.
Chris wrote:Like the C++ standard library? :?
The C++ standard library literally has to link over the C++ ABI.
Post Reply