Object-orientation in C

前端 未结 22 1709
孤城傲影
孤城傲影 2020-11-22 15:26

What would be a set of nifty preprocessor hacks (ANSI C89/ISO C90 compatible) which enable some kind of ugly (but usable) object-orientation in C?

I am familiar with

22条回答
  •  旧时难觅i
    2020-11-22 16:04

    For me object orientation in C should have these features:

    1. Encapsulation and data hiding (can be achieved using structs/opaque pointers)

    2. Inheritance and support for polymorphism (single inheritance can be achieved using structs - make sure the abstract base is not instantiable)

    3. Constructor and destructor functionality (not easy to achieve)

    4. Type checking (at least for user-defined types as C doesn't enforce any)

    5. Reference counting (or something to implement RAII)

    6. Limited support for exception handling (setjmp and longjmp)

    On top of the above it should rely on ANSI/ISO specifications and should not rely on compiler-specific functionality.

提交回复
热议问题