Isn’t there a chicken-and-egg issue since GCC is written in C++ itself?

Since 4.8 release, the C++ compiler GCC (the G++ part of it) is written not in C anymore, but in C++ itself. I have a hypothetical question on this.

I wonder how to compile the C++ code of GCC on a new platform that has no C++ compiler yet. Of course, you could use prebuilt binaries compiled on other machines. Or you could use an older version of GCC that was written in C and compile the current version with it.

However, without prebuilt binaries and just the newest version, you were stuck, right? If not, are there other implications on this situation raised by the switch from C to C++ of the GCC project?

7

This is actually a well-known concept called bootstrapping. Basically, there exists, somewhere, a minimal C codebase to build a version of GCC that’s capable of building the current GCC codebase. Self-hosting languages have been doing things like that for decades.

3

Creating a compiler that is written in the same language that it compiles is called bootstrapping. The wikipedia article describes a number of ways that a compiler can be bootstrapped.

Given your restriction that you only have a post-4.8 G++ source code and no pre-built binaries for your target platform (no existing C++ compiler), then bootstrapping the G++ compiler can be done by means of cross-compilation.

When bootstrapping a compiler using cross-compilation, you build several versions of your compiler

  1. On your PC, you install a C++ compiler (can be any C++ compiler, doesn’t have to be G++)
  2. Using that compiler, you create a G++ cross-compiler that can execute on the PC and generates code for the target platform
  3. Using the G++ cross-compiler you just built, you create a native G++ compiler that can run on the target platform and create code for it.
  4. You are done. You have created a C++ compiler for the new platform.

If you also don’t have a PC (or similar) to perform the initial steps on, then you are indeed stuck, but the chance of being in that situation and trying to bootstrap a compiler are negligible.

What would happen if some virus managed to delete all existing compiled C++ compilers, including all backups, and all C++ compilers were written in C++? We would still have source code to C++ compilers.

We would have a problem. We couldn’t compile any C++ code whatsoever because we have no compiled C++ compilers. We couldn’t build any of the C++ compilers that we have source code for because they are all written in C++. What would we do?

We would look for the best compiler that we can find. Maybe we find a compiled C or C# compiler. We could use that to compile and run C or C# code. We would then take our C++ source code for a C++ compiler, translate it manually to C or C#, compile it, and use that to compile the C++ source code.

We would have left out any code for optimising C++ code, or for compiling C++ features not used by the C++ compiler in our C or C# version, so the result wouldn’t be a good or complete C++ compiler. But it would be good enough to compile our C++ compiler, so we’d have a slow (unoptimised) compiler for the complete language. We compile our C++ compiler source code again with this version, and now we have our original compiler back.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Isn’t there a chicken-and-egg issue since GCC is written in C++ itself?

Since 4.8 release, the C++ compiler GCC (the G++ part of it) is written not in C anymore, but in C++ itself. I have a hypothetical question on this.

I wonder how to compile the C++ code of GCC on a new platform that has no C++ compiler yet. Of course, you could use prebuilt binaries compiled on other machines. Or you could use an older version of GCC that was written in C and compile the current version with it.

However, without prebuilt binaries and just the newest version, you were stuck, right? If not, are there other implications on this situation raised by the switch from C to C++ of the GCC project?

7

This is actually a well-known concept called bootstrapping. Basically, there exists, somewhere, a minimal C codebase to build a version of GCC that’s capable of building the current GCC codebase. Self-hosting languages have been doing things like that for decades.

3

Creating a compiler that is written in the same language that it compiles is called bootstrapping. The wikipedia article describes a number of ways that a compiler can be bootstrapped.

Given your restriction that you only have a post-4.8 G++ source code and no pre-built binaries for your target platform (no existing C++ compiler), then bootstrapping the G++ compiler can be done by means of cross-compilation.

When bootstrapping a compiler using cross-compilation, you build several versions of your compiler

  1. On your PC, you install a C++ compiler (can be any C++ compiler, doesn’t have to be G++)
  2. Using that compiler, you create a G++ cross-compiler that can execute on the PC and generates code for the target platform
  3. Using the G++ cross-compiler you just built, you create a native G++ compiler that can run on the target platform and create code for it.
  4. You are done. You have created a C++ compiler for the new platform.

If you also don’t have a PC (or similar) to perform the initial steps on, then you are indeed stuck, but the chance of being in that situation and trying to bootstrap a compiler are negligible.

What would happen if some virus managed to delete all existing compiled C++ compilers, including all backups, and all C++ compilers were written in C++? We would still have source code to C++ compilers.

We would have a problem. We couldn’t compile any C++ code whatsoever because we have no compiled C++ compilers. We couldn’t build any of the C++ compilers that we have source code for because they are all written in C++. What would we do?

We would look for the best compiler that we can find. Maybe we find a compiled C or C# compiler. We could use that to compile and run C or C# code. We would then take our C++ source code for a C++ compiler, translate it manually to C or C#, compile it, and use that to compile the C++ source code.

We would have left out any code for optimising C++ code, or for compiling C++ features not used by the C++ compiler in our C or C# version, so the result wouldn’t be a good or complete C++ compiler. But it would be good enough to compile our C++ compiler, so we’d have a slow (unoptimised) compiler for the complete language. We compile our C++ compiler source code again with this version, and now we have our original compiler back.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật