Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Why does GCC compile with C++?

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the knowledge of "Why GCC is compiled with C++". In the operation of practical cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Why use C++?

In GNU's C++ Conversion document, we can see a description like this in Background:

Whether we use C or Clearing, we need to try to ensure that interfaces are easy to understand, that the code is reasonably modular, that the internal documentation corresponds to the code, that it is possible for new developers to write new passes and to fix bugs. Those are the important issues for us to consider. The C++ features which are not present in C-features which are well documented in many books and many web sites-are not an important issue.

The meaning of this sentence can be understood that today GCC is a bit hold in the implementation of C language, because developers feel that no matter whether we use C or C tools, we need to work hard to ensure that the interface is easy to understand, so that our code wants to be rationally modularized, so that the internal documentation is consistent with the code, so that the code can be better organized, which is beneficial to the newcomer fix-bug. And C++ can enable them to finish these things better.

GNU also gives the following reasons:

C++ is a standardized, popular and popular language.

C++ is a superset of C90.

C++ as an extension of C is as good as C in performance.

C++ supports cleaner code in some meaningful cases.

C++ makes it easier for you to write a cleaner interface.

C++ will never make your code uglier.

C++ is not a panacea, it is an improvement of C.

The operation of data structure-- your writing will not be as good as STL.

Structure sleeve structure or inheritance?

Function pointer or polymorphism?

Garbage collection or smart pointer?

Why not Clippers?

Is C++ slow? Some features will be slow, but sometimes C++ is faster, you can only use your favorite C++ feature.

Is C++ complicated? It's just another programming language that makes it easier for you to maintain to programmers.

FSF doesn't like caterpillars! Because FSF (Free Software Foundation) these people don't write code.

Bootstrapping

* I'd like to introduce Bootstrapping. The so-called Bootstrapping is to write a compiler in your own language to compile yourself, that is to say, if you want to compile gcc, you need to use a c compiler to compile it. This is bootstrapped process, the bootstrap process. Including BASIC, Algol, C, Clearing, Pascal, PL/I, Factor, Haskell, Modula-2, Oberon, OCaml,Common Lisp, Scheme, Java, Python, Scala and other languages.

The main advantage of this is that you can test yourself, and the improvement of the compiler and the improvement of the language complement each other.

However, this is a "chicken egg or egg chicken" question, if you need to write an X language compiler language in X language, you can do this:

Use Y language to implement X's language interpreter or compiler. Niklaus Wirth says Pascal's * compilers are written by Fortran.

There is already a compiler or interpreter for X language written in Y language. That's what Scheme did.

There is already a compiler to compile an earlier version of the X language, and then you can use the earlier version of the X language to compile the new version of the X language. That's what Java,Haskell and the original version of Free Pascal did.

A compiler for X already exists on one platform, and cross-compilation techniques can be used to compile the X language on another platform, as the C language does.

Write a compiler in X, and then compile it manually (no special optimization is required), (Note: manual compilation is estimated to be manually translated into machine assembly code), and then run the manually compiled compiler to compile the compiler's source code. and optimize it. Donald Knuth uses this method in his WEB literate programming system.

This is the end of the content of "Why GCC is compiled with C++". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report