Should I learn to implement OOP in C? Are there projects that use OOP in C?

前端 未结 6 626
闹比i
闹比i 2020-12-28 17:50

Recently, I finished reading K&R with its, almost all, exercises and examples. I was planning to move to \"Accelerated C++\" that I came across Axel Schreiner\'s book OO

6条回答
  •  隐瞒了意图╮
    2020-12-28 18:39

    I've had experience with several advanced C projects which make at least some use of OOP. The most well known is the Linux kernel.

    The kernel is entirely C (except for platform specific pieces in assembly for hardware interfaces).

    The kernel makes heavy use of structures with function pointers in many places. The first that comes to mind is file systems. Drivers fill in the file_operations struct (as well as many others) with callbacks to their specific implementations.

    The kernel also makes a lot of use of goto statements which in some contexts can be thought of as rudimentary throw statements leading a label at the end of the function to do some clean-up and exit. (Though they do also use goto for a lot more than just error handling, and it is also only used for "exceptions" within a function, not for passing them outside.)

提交回复
热议问题