问题描述
在 C 中启用某种丑陋(但可用)的面向对象的一组漂亮的预处理器技巧(ANSI C89/ISO C90 兼容)是什么?
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?
我熟悉几种不同的面向对象语言,所以请不要回答学习 C++!"之类的答案.我已经阅读了 "Object-Oriented Programming With ANSIC"(注意:PDF 格式)和其他几个有趣的解决方案,但我最感兴趣的是你的 :-)!
I am familiar with a few different object-oriented languages, so please don't respond with answers like "Learn C++!". I have read "Object-Oriented Programming With ANSI C" (beware: PDF format) and several other interesting solutions, but I'm mostly interested in yours :-)!
推荐答案
C 对象系统 (COS)听起来很有希望(它仍处于 alpha 版本).为了简单和灵活,它尽量减少可用的概念:统一的面向对象编程,包括开放类、元类、属性元类、泛型、多方法、委托、所有权、异常、契约和闭包.有一份描述它的草稿 (PDF).
C Object System (COS) sounds promising (it's still in alpha version). It tries to keep minimal the available concepts for the sake of simplicity and flexibility: uniform object oriented programming including open classes, metaclasses, property metaclasses, generics, multimethods, delegation, ownership, exceptions, contracts and closures. There is a draft paper (PDF) that describes it.
C 中的异常 是 TRY-CATCH-FINALLY 的 C89 实现在其他面向对象语言中找到.它带有一个测试套件和一些示例.
Exception in C is a C89 implementation of the TRY-CATCH-FINALLY found in other OO languages. It comes with a testsuite and some examples.
两者均由 Laurent Deniau 撰写,他在 C 中的 OOP 方面做了大量工作.
Both by Laurent Deniau, which is working a lot on OOP in C.
这篇关于C 语言中的面向对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!