5 ms·
> Given the central role that C continues to play in systems software, and the difficulty of writing safe and correct C code, it remains a grand challenge to de
by visualradio 5y ago
> Given the central role that C continues to play in systems software, and the difficulty of writing safe and correct C code, it remains a grand challenge to develop effective formal methods for verifying C programs.
One of the reasons C likely continues to play a large role in systems programming, despite regularly highlighted defects by researchers, is because new language designers have largely given up on concept of header files and forward declaration.
When a standards organization wants to work with hardware vendors to define a cross-platform interface in terms of human readable symbols rather than explicit values, with the possibility of many competing private translations, C is a natural choice because header files provide a necessary bridge or abstraction.
It would be interesting if a 'Better C' language was also a 'Better H' language and provided a literate interface declaration formats without macros or inline functions. Eliminating support for macros and inline functions from headers, and making inlinability a private implementation detail, should not theoretically prevent future compilers from inlining implementation code from multiple sources into a single unit as a performance optimization.
- kubb 5y agoThis is a bizarre take on the popularity of C. It completely ignores the notions of existing ecosystems (compilers for every platform, kernel code, immense number of APIs) and programmer population (C is taught in every uni). Instead it ties down C's popularity to the language's ability to separate interface from implementation via header files, and claims no other language can achieve that. It also overlooks the downsides of header files (like unnecessary recompilation).
- deleted 5y ago[deleted]
- kubb 5y agoUpon some reflection, I could add to the list of reasons for the popularity of C: * Interop with every language. * Existing codebases. * Years of virtual platform excusivity in embedded systems, and OS. * Momentum (people like to get into things that are popular).
- qsort 5y agoI think the fundamental reason is that there aren't that many alternatives. Of course, if I were to write application software of any kind I wouldn't choose C, but for things like FFI/interop or embedded, anything that isn't C, C++ or Rust is a complete non-starter, and even C++ and Rust are often a stretch.
- kaba0 5y agoHow is C++ a stretch? I don’t think there is any domain left where C++ would not be applicable but C is.
- lelanthran 5y ago> How is C++ a stretch? I don’t think there is any domain left where C++ would not be applicable but C is. Reusable code. Your library written in C++ can't be called as easily from Python, PHP, Perl, C, Pascal, Rust, Go or any of the other languages people like to use. Just do a search for uses of libffi and you'll get a pretty good idea why C is still more popular than C++.
- xyzzyz 5y agoThat’s not true. C++ code can be called from foreign languages just as easily as C, you just have to provide C-like interface and mark it as extern “C”.
- qsort 5y agoSure, but that means I have to provide the interface myself. One of the main advantages of C++ over C is that you don't have to pass around pointers to structs, so you're stuck between using C++ as basically C, or duplicating every object the API needs to expose. Obviously you can make it work, and it probably makes a lot of sense for larger libraries where the advantages of working with C++ really pull their weight, but regardless, FFI is still one of the (admittedly fewer and fewer) niches where C shines.
- zokier 5y agoBut even C doesn't really have header files from language viewpoint. The compiler doesn't make distinction between code coming from a .h file or a .c file. Heck, I can't name a single language off-hand that would have explicit header-file like mechanism. Edit: I suppose JavaScript + WebIDL would fit? Although nobody uses them, except browsers themselves.
- docandrew 5y agoAda is one. It splits the interface (specification) and implementation (body) into separate files (.ads and .adb). This is also unlike C which just does a "copy-and-paste" wherever the #include occurs. This also makes its formal verification (SPARK dialect) nice because you can add pre and post-conditions to the interface without cluttering up the code body.
- nullifidian 5y ago>I can't name a single language off-hand that would have explicit header-file like mechanism. Ocaml's .mli files?
- jcelerier 5y agoC++20 has module interface units and module implementation units
- wffurr 5y agoIt’s trivial to write interface definitions in just about any language, and have the implementation be separate.
- deleted 5y ago[deleted]