5 ms·
> 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 Linu
by i-am-curious 6y 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.
- ricattierger 6y agoWhy 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.
- hellofunk 6y 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.
- bregma 6y agoThey 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.
- account42 6y agoNitpick: gcc and g++ are not different frontends but different compiler drivers. They can both invoke the C and C++ frontends (cc1 and cc1plus) and select them based on the file extension unless specified using the -x option. The difference between gcc and g++ is mainly in which libraries are linked by default.
- bregma 6y agoWell, it's true that the different compilers are cc1 and cc1plus, but given most programmers I've run into here in vacuumland have trouble distinguishing between their IDE and their toolchain, expecting them to understand the difference between the actual compiler invoked by the driver depending on a file extension or '-x' switch vs. the different compiler driver that invokes that compiler by default for a given file extension is a bit of a stretch. Even you seem to be confused by the compiler proper (cc1 or cc1plus) and the front end (the part of each compiler that parses the code and builds an internal representation that then gets passed on to the middle end for optimization and the back end for register allocation and instruction generation). The fact is, the front ends of cc1 and cc1plus will interpret the exact same C code differently to the extent that code containing undefined behaviour will have remarkably different results in the generated instructions. The differences between the cc1 and the cc1plus compilers are not limited to what the compiler driver passes to the linker, they have completely different front ends and only share the middle and back ends.
- account42 6y ago> Even you seem to be confused by the compiler proper (cc1 or cc1plus) and the front end (the part of each compiler that parses the code and builds an internal representation that then gets passed on to the middle end for optimization and the back end for register allocation and instruction generation). Sure, the cc1 and cc1plus binaries come with a middle and backend linked in, but what differentiates them is the front end. Not so much for gcc and g++ where both `gcc file.cpp` and `g++ file.cpp` will invoke cc1plus. Not to mention that with LTO cc1 and cc1plus do almost exclusively front end work while everything else happens in lto1 (for both C and C++).
- Nginx487 6y agoI 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 6y agoThe 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 6y agoWith 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 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 https://gcc.godbolt.org/z/1vbqo3
- bregma 6y agoThe "zero-cost abstraction" concept is that you don't pay for something you don't use. If you use a smart pointer, you pay for it. If you don't use a smart pointer, it's zero cost. Any argument that smart pointers are not zero cost to the language because they have a cost when you use them is a classic straw man argument.
- pizza234 6y agoWhat'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 6y agoJohn 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.
- hellofunk 6y agoStrange 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 6y agoAny examples of using compile time features that make a difference, instead of making code harder to maintian and increasing compile times significantly?
- hellofunk 6y agoYou’re talking about really two different issues here. I don’t think anyone would suggest templates can’t get complicated. But they are certainly the doorway into maximum performance over C.
- jstimpfle 6y agoNo I don't think I'm talking about something else. And I wouldn't submit to the opinion that performance cricitical code needs to be written in C++. For example, Games are heavy in C++ where there are a lot of abstractions. Engine code is mostly C style as far as I can tell. Optimized code is code that exploits specific properties of systems, hence it is significantly less abstracted than higher-level code. The stereotypical std::sort example doesn't count, really. There are many reasons why std::sort vs qsort (which are both generic sorting implementations - i.e. not optimized ones) is not significant in practice, but it's still among the most frequently cited examples - hinting that there might be few real wins (with regards to performance) from all this compile time and templates stuff.
- hellofunk 6y agoHm, I’m not sure where to start with your assessment here. Your comments on sorting don’t really seem relevant, I don’t think you’re referring to the same kind of compile time programming we’ve been discussing. There’s a difference between generic code, and code that runs at compile time, even though both might actually use the C++ feature of templates. C++ templates are way to write code that supports generics, but they are also a way to do a style of programming referred to as “meta-programming“, these are really not the same thing at all. While you can certainly do without generics in the language, as proven by the success of many many languages, perhaps at the inconvenience of some developers, compile time meta programming is an entirely different area that only few languages really support. The high frequency trading firms and the game studios I have partnered with are typically using C++ specifically for those compile time programming features. They make dramatic performance differences in a wide range of highly specialized algorithms.
- rvz 6y agoYet 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 6y agoOriginal cross-platform Netscape was iirc. Quality died when they went to c++? Probably less influential on their fate than Microsoft.
- jcelerier 6y ago> Quality died when they went to c++? when they went to c++ it became Firefox. do you think we'd have a better firefox today had it stayed in C ?
- harry8 6y ago/When/ they went, which, iirc was Netscape 4 (?). It was horrendous, crashing, slow buggy, awfulness, which the previous version really wasn't. This was when it was all closed and proprietary. Firefox came a long time later. Well after Mozilla opened. No idea if Firefox would be better if they'd stayed in c. What i do know is that c++ is a vastly, vastly better language now through no fault of the standards committee. G++ got good. Then came clang++, valgrind was an amazing leap forward too. Before all that there really was no such thing as cross platform c++.
- deleted 6y ago[deleted]