News for hackers. Stuff that matters.
Re:A proposal to start “llvm-libc” (2020) by flohofwoe on Tuesday December 07, 2021 @06:29PM (#29479517)
> but take advantage and use C++ language facilities for the core implementation.

This point sticks out. Would be nice to get some more details why it would make sense to use C++ for the implementation instead of C.

Re:A proposal to start “llvm-libc” (2020) by maccard on Tuesday December 07, 2021 @06:44PM (#29479636)
Raii is enough of a reason IMO, but templates, type safety, actual arrays, constexpr, and various modern changes to the language that allow for the compiler to optimise code (move semantics and RVO)
Re:A proposal to start “llvm-libc” (2020) by dralley on Tuesday December 07, 2021 @08:57PM (#29480495)
Those are all fantastic reasons to use relibc, the libc written in Rust, which has the additional benefit of already existing.

https://gitlab.redox-os.org/redox-os/relibc

Re:A proposal to start “llvm-libc” (2020) by maccard on Thursday December 09, 2021 @07:33AM (#29496627)
Sorry I missed this reply. I do'nt disagree, but honestly at this point anything is better than using C for libraries like this.
Re:A proposal to start “llvm-libc” (2020) by mhh__ on Tuesday December 07, 2021 @07:30PM (#29480011)
Function overloading and more places to use default values was enough to make me go mental last time I had to use strict C as opposed to limited C++
Re:A proposal to start “llvm-libc” (2020) by MarkSweep on Tuesday December 07, 2021 @07:14PM (#29479910)
On a related note, Microsoft has also talked about refactoring their C run time to be written in C++. They give some reasons like maccard mentions I a comment next to this: features like RAII and templates make code easier to maintain than manual memory management and ifdefs.

https://devblogs.microsoft.com/cppblog/the-great-c-runtime-c...

Re:A proposal to start “llvm-libc” (2020) by pjmlp on Wednesday December 08, 2021 @01:51AM (#29481946)
Easy, C++ is more type safe than C since forever. Also the same reasoning why GCC has migrated to C++.

Microsoft has done the same with their new C runtime, and they have written a couple of blog posts exactly about that subject.

From "The Great C Runtime (CRT) Refactoring"

> So, as part of this great refactoring of the CRT, we have done an enormous amount of work to simplify and improve the quality of the code, so that it is easier to add features and fix bugs in the future. We have converted most of the CRT sources to compile as C++, enabling us to replace many ugly C idioms with simpler and more advanced C++ constructs. The publicly callable functions are still declared as C functions, of course (extern "C" in C++), so they can still be called from C. But internally we now take full advantage of the C++ language and its many useful features.

-- https://devblogs.microsoft.com/cppblog/the-great-c-runtime-c...

"C Runtime (CRT) Features, Fixes, and Breaking Changes in Visual Studio 14 CTP1"

https://devblogs.microsoft.com/cppblog/c-runtime-crt-feature...

"Introducing the Universal CRT"

https://devblogs.microsoft.com/cppblog/introducing-the-unive...

Re:A proposal to start “llvm-libc” (2020) by zemoo on Tuesday December 07, 2021 @07:09PM (#29479860)
The Microsoft C standard library implementation also takes this approach - C++ implementation with C exports, for the reasons called out by the sibling comments.
Re:A proposal to start “llvm-libc” (2020) by AndyKelley on Tuesday December 07, 2021 @07:53PM (#29480152)
This project is dead in the water if the resulting libc depends on libc++ at runtime.
Re:A proposal to start “llvm-libc” (2020) by silverlyra on Tuesday December 07, 2021 @09:25PM (#29480623)
I wondered if that’s why the proposal words it as “use C++ language facilities” instead of just “use C++” – use the C++ language, but not its stdlib.

I found this internal file that forms the basis of all the atoi and strol family functions. Seems like they do get some nice wins from the C++ language, without needing (e.g.) STL: https://github.com/llvm/llvm-project/blob/main/libc/src/__su...

Re:A proposal to start “llvm-libc” (2020) by scrb on Wednesday December 08, 2021 @12:48PM (#29487932)
As somebody else has already said, the idea is to use the c++ language and not its runtime or the standard library. In fact, there are a few clang-tidy checks for llvm libc to protect from accidentally using pieces from other libraries (like the system libc and the c++ standard library.) https://clang.llvm.org/extra/clang-tidy/checks/llvmlibc-call... https://clang.llvm.org/extra/clang-tidy/checks/llvmlibc-impl... https://clang.llvm.org/extra/clang-tidy/checks/llvmlibc-rest...
Re:A proposal to start “llvm-libc” (2020) by SubjectToChange on Wednesday December 08, 2021 @02:42AM (#29482201)
Systems like game consoles or Fuchsia only need a libc for POSIX compatibility, this would work well for them.
Re:A proposal to start “llvm-libc” (2020) by pjmlp on Wednesday December 08, 2021 @01:53AM (#29481954)
Many others have already trailed this path like e.g. Microsoft in 2014.
Re:A proposal to start “llvm-libc” (2020) by xyzzyz on Tuesday December 07, 2021 @07:54PM (#29480155)
It’s much easier to write safer code in C++ than in C. You can still shoot yourself in the foot, but unlike C, modern C++ at least helps you avoid that.
Re:A proposal to start “llvm-libc” (2020) by flohofwoe on Wednesday December 08, 2021 @04:42AM (#29482789)
If safety is a concern they would have gone the Rust route though. Is C++ easier to fuzz and statically analyze than C? I'd doubt that tbh.
Re:A proposal to start “llvm-libc” (2020) by johnisgood on Wednesday December 08, 2021 @05:10AM (#29482989)
Or Ada. I wish AuroraUX was still alive. :(
Re:A proposal to start “llvm-libc” (2020) by rightbyte on Wednesday December 08, 2021 @10:41AM (#29486067)
I would say that you need to know alot more to get to the point where writing C++ is easier than C, though.
Re:A proposal to start “llvm-libc” (2020) by mhh__ on Tuesday December 07, 2021 @06:49PM (#29479686)
Other than platform support I think C is practically only a hindrance compared to C++ in the hands of competent developers.