Crest-Let's copy a gobject.

Source: Internet
Author: User

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:

    1. Uncover the so-called "Object-Oriented"Programming LanguageThe mysterious veil of, to lead everyone to the depth of the programming language travel.
    2. Test the depth of C language in carrying new language features
    3. Demonstrate the powerful functions and shortcomings of macro definition (macro) in C series
    4. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.