Re: The Case for Rust (in any system)
Date: Mon, 09 Sep 2024 07:01:42 UTC
On 8 Sep 2024, at 22:11, Poul-Henning Kamp <phk@phk.freebsd.dk> wrote: > > Warner Losh writes: > >> I did C++ in the kernel in the 4.x->7-current time frame. > > The logical progression of C++ adoption would start with using a C++ > compiler as a better C compiler. I’m always a bit nervous about this: C’s struct initialiser syntax is useful for things that look like optional parameters in C APIs but is invalid in C++. I believe clang and gcc support it in C++ mode in some places, but I’m not sure where. C++ has stricter aliasing rules than C. Some things that are valid C and will do the right thing with -fstrict-aliasing will incorrectly compile in C++ mode. C permits implicit casts from void*, C++ doesn’t. The last codebase I worked on that had gone through this transition was littered with implicit casts which made it hard to read. At a minimum, I’d want to add an always-inline templates wrapper around malloc that did the right thing, if not an explicit move to new/delete. C++ places type and value names in the same namespace. There are some corner cases where a structure and a variable have the same name and sizeof gives different results in C and C++ modes. Compiling C as C++ will *normally* give the same output, but not always. David