Thanks to the two bo in garden for providing us with gobject-related knowledge (refer to the series "using C language for object-oriented development-getting started with gobject" and "playing with Vala"). inspired by them, they decided to create a system similar to gobject. In popular words, it was called "shanzhai. We hope bigtall will be able to make a cheap, high-quality, and lightweight "shanzhai" product this time.
The purpose of this operation is as follows:
- Uncover the so-called "Object-Oriented"Programming LanguageThe mysterious veil of, to lead everyone to the depth of the programming language travel.
- Test the depth of C language in carrying new language features
- Demonstrate the powerful functions and shortcomings of macro definition (macro) in C series
- If bigtall's new features are better than the original gobject, it may be useful.
First, bigtall should give me a proper name for the "shanzhai" feature. Well, I think the name "shanzhai" is really good, but it is not easy to translate it into English? First, let's look at the top of the mountain. It explains that knap = the crest of a hill is pleasing to the eye and it means: "The crown, (on the helmet) the feather, (especially on the mountain) top ". Good! It is crest.
Secondly, we need to list our requirements, that is, the "Object-Oriented" feature list to be implemented. However, bigtall does not know how many functions can be implemented, let's "ride a donkey to read the album -- just walk away.
- Class (including duck type)
- Interface
- Class and interface inheritance (including class single inheritance, class multi-inheritance, interface implementation and inheritance, prototype inheritance)
- Call member functions (including common members, virtual functions, and pure virtual functions)
- Attribute
- Type check and conversion
- Object creation and destruction (constructor and destructor)
- Object Memory Allocation and release mechanism (new, delete)
- Message, event, and signal mechanisms
- Closure
- Reflection reflection
- Debugging support
- Multithreading
Bigtall is not familiar with functional languages, so if you have any other interesting features, please provide them as we are in the form of research and discussion, so you don't have to worry about the final implementation. And thisArticleA series should be written. bigtall wants to present a complete process of "Design, compromise, and balance.
Before entering the topic, bigtall also wants to say two more words. When using the C language, we must note that one of its features is "no exception handling" (setjump may be counted ). The laughter brought by this feature is that the exit of any function is well designed and there will be no exception, exception, and throw.CodeIt is easy to run. The disadvantage is that it is annoying to judge the exit code.
Next article:
Design of simple crest objects