Re: [PATCH 00/45] C++: Convert the kernel to C++

From: Chris Down
Date: Thu Jan 11 2024 - 07:39:45 EST


H. Peter Anvin writes:
We already *do* use constructors and *especially* destructors for a lot of objects, we just call them out.

Note that modern C++ also has the ability to construct and destruct objects in-place, so allocation and construction/destruction aren't necessarily related.

There is no reason you can't do static initialization where possible; even constructors can be evaluated at compile time if they are constexpr.

Side note for the constructor and destructor discussion: should we be more widely marketing the __cleanup() infrastructure that Peter added a year or so ago? It likely helps a lot with at least some of these cases. In systemd we use __attribute__((cleanup)) pretty widely and my experience is that it's made the code a lot easier to both create and consume.