top | item 24361303

(no title)

i-am-curious | 5 years ago

> I don't see modern application of C outside embedded,

C is one of the most popular languages for high-performance code. Most famous example would be the Linux kernel but literally anything that needs the best optimizations possible eventually comes down to C.

discuss

order

hellofunk|5 years ago

Strange thing to say, to be honest. Many of the most performance-critical industries are heavy on C++, not C. Games, finance, high-frequency trading, where every microsecond is worth huge money -- these are typically C++ shops. The strictness and ability to move things to compile time are features not available in C.

jstimpfle|5 years ago

Any examples of using compile time features that make a difference, instead of making code harder to maintian and increasing compile times significantly?

Nginx487|5 years ago

I worked under ULL trading platform, they used C++ with heavy templates, without RTTI and exceptions. If things can be done in compile time, it should be done - which is the purpose of templates. Neither our nor neighbor teams (near 800 developers) used plain C. As Bjarne Stroustrup told, there's no place between C++ and machine code for "more low-level language", everything which could be done in C, also could be done in C++ with the same efficiency.

Good tendency however, now both C and C++ developers started experimenting with Rust, probably creating unified community and platform.

harry8|5 years ago

The problem is the one you state.

You have to use a subset of c++. Nobody agrees what that subset is. You have to be super-vigilant in code review. Features invite their use.

It's the lack of features in c that make it attractive. No magic. You want an object or a virtual, code it up if you really mean it is not just a keyword. You take responsibility for all the code running.

Every time I've cut a tonne of latency from a trading engine it's that. People relying on library and compiler without taking responsibility for it. STL is great. Except if you're actually performance critical, when you can beat it easily by solving your problem, not someone else's solution for everyone's possible similar problem.

mehrdadn|5 years ago

With the caveat that I am NOT suggesting this justifies choosing C over C++, I just wanted to mention this talk about how "zero-cost abstraction" is an idealism, not necessarily a reality: https://www.youtube.com/watch?v=rHIkrotSwcc&t=17m30s

That said, I tried to reproduce something similar, and it seems the issue only occurs in my example due to external linkage (adding 'static' fixes it)... but I can't claim this will always resolve the issue: https://gcc.godbolt.org/z/1vbqo3

pizza234|5 years ago

What's your judgment on the Doom 3 source code? It's something performance critical, but it's in C++; Sanglard's review of the design codebase was very positive.

clktmr|5 years ago

John Carmack wrote in 2010: > There is some decent code in Doom Classic, but it is all C, and I would prefer to do new game development in (restrained) C++.

> I had been harboring some suspicions that our big codebases might benefit from the application of some more of the various �modern� C++ design patterns, despite seeing other large game codebases suffer under them. I have since recanted that suspicion.

I think this shows that C++ works better in controlled (i.e. corporate environments), whereas C is often preferred in Open Source.

ricattierger|5 years ago

Why do you say that? Certain things in a language may increase binary size or something else but at the end of the day these languages all go through most likely the same compiler and should produce a roughly equivalent binary.

bregma|5 years ago

They will produce equivalent binaries, but not identical binaries.

For example, GCC's C++ front end will produce a different parse tree for the same C code as the C front end, resulting in a slightly different collection of basic blocks and data flow analysis (obviously, for very trivial examples, it will be identical). The result after all the gimplification and and different middle-end passes and rtl transformations you can end up with a surprisingly different set of generated instructions for the same code fed to gcc and g++. Equivalent, but different.

hellofunk|5 years ago

> these languages all go through most likely the same compiler and should produce a roughly equivalent binary

That's not really true. A single compiler may support many languages but that does not mean code written in those languages ends up as the same binary.

rvz|5 years ago

Yet the 'modern web browsers' we're all using are probably written in C++.

I'm yet to see a 'modern web browser' that is fully written and only written in C. (C bindings don't count)

harry8|5 years ago

Original cross-platform Netscape was iirc. Quality died when they went to c++? Probably less influential on their fate than Microsoft.