Some may make an argument that kernel things like VM or VFS are "object oriented".Well, you can argue that both hardware drivers and filesystems in operating system kernels are very object-oriented, including inheritance.
They just don't use an OO language. Except on macOS.
It's possible: one particular interrupt could serve one particular device, there are multiple devices in the system (each using one object), and the ISR is then a method of a particular device.writing an interrupt driver in OO doesn't make sense,
In the late 1980s, there was a really nice guy from Stanford's SLAC accelerator control group who wrote a little text book: "Object oriented programming in C". And no, he didn't mean C++, he meant C. It's doable. The resulting code tends to look a bit verbose and scattered, but once you learn the idiom, it's pretty obvious. It relies on lots of calling via function pointers; and if you want virtual functions in the inheritance graph, you either put function pointers into your struct, or each struct has a pointer to another per-class struct that holds the function pointers (equivalent to the vtable).They just don't use an OO language. Except on macOS.
absolutely...I've always strived to use an opaque pointer handle to an object with a well defined API when I wrote SO libraries. In fact, my embedded code frequetnly uses OO idioms so that it makes sense to me (if it reaches a certain degree of complexity)...However, I still prefer writing classes in C++. Well, other than an application God class...I've never had use for such things, although some OO guys are in love with the bloody things.In the late 1980s, there was a really nice guy from Stanford's SLAC accelerator control group who wrote a little text book: "Object oriented programming in C". And no, he didn't mean C++, he meant C. It's doable. The resulting code tends to look a bit verbose and scattered, but once you learn the idiom, it's pretty obvious. It relies on lots of calling via function pointers; and if you want virtual functions in the inheritance graph, you either put function pointers into your struct, or each struct has a pointer to another per-class struct that holds the function pointers (equivalent to the vtable).
Sadly, I can't remember the name of the guy. The book is probably in a cardboard box in the basement, not having been looked at in a few decades. Chuck or Charles Something?
If you look at OO this way, you quickly see that kernels tend to be very very OO. From there, it is only a small leap to use languages that explicitly support OO in the kernel, which can be done; I know some commercial projects that use C++ in the Linux kernel.
calling C code from a C++ program is the preferrable direction, and it's not hard. just remember to wrap the C func declarations in an extern "C" wrapper so they don't get name mangled. I generally warn people against going the other direction, although it is also possible.kent_dorfman766 good insight. One "problem" I've run into is "library C++ but someone wants to call it from C" or the converse of "Library in C and caller is C++". Doable, but you need to figure out the interface and compiler/linker options to constrain things.
class Counter
@x : Int32
def initialize(x : Int32)
@x=x
end
def setx(x : Int32)
@x=x
end
def getx : Int32
@x
end
def add1
@x=@x+1
end
end
c : Counter=Counter.new(3)
c.setx(5)
c.add1
puts c.getx
Agree it's not hard. But if one is providing a shared library you need to think about it before you get complaints.calling C code from a C++ program is the preferrable direction, and it's not hard. just remember to wrap the C func declarations in an extern "C" wrapper so they don't get name mangled. I generally warn people against going the other direction, although it is also possible.
Maturin posted the link to the pdf in post #40 here.In the late 1980s, there was a really nice guy from Stanford's SLAC accelerator control group who wrote a little text book: "Object oriented programming in C".
Same topic, different book. I haven't found the one I remember yet; it was quite a few years earlier than the one Maturin linked to.Maturin posted the link to the pdf in post #40 here.
You don't need to link it, but it was nice if you could remember at least title, and author.Same topic, different book. I haven't found the one I remember yet; it was quite a few years earlier than the one Maturin linked to.
I ended up with a negative view of OO programming.
C++ of course invests most of the recent development (much of those 1000 pages) into facilities that are not object-oriented.
There's also a quote "Object orientation is in the mind of the programmer, not in the compiler" or something like that. I think it was Alan Cox, but I can't find a reference and am not sure."I invented the term 'Object-Oriented', and I can tell you I did not have C++ in mind."
- Alan Kay