I was looking at a list of new features in the different C versions, and I was wondering, how are features implemented in a language? For example, if C was to add new features into the language, would they code the features in by using the C language itself? Or is another technique to modifying the language?
CodePudding user response:
As you weren't specific about particular features, I'll give you answer only for the last part of your question
would they code the features in by using the C language itself
Yes, they are. This process is called compiler bootstrapping. The simplest explanation of the process:
Write the first version of a compiler on any programming language (e.g. assembler), which allow you implement basic constructions on your new language (C in your case)
Rewrite this logic on your new language :)
Continue add new features until you're satisfied
CodePudding user response:
I diagree with the "bootstrapping" answer - as Richrad Critten notes in the comments, that hasn't been done in decades. It's entirely obsolete.
Languages like C and C are compiled. That is to say, there is a program called a compiler, which reads source code (text) and emits binary code that can be directly executed on the CPU.
The basics of this are not very hard - languages such as C are built around function calls, and every CPU from the last few decades has direct support for that.
Sure, new standards add new functions to the Standard Library, but that just means that the compiler comes with a set of pre-written functions. For quite a few of those functions, earlier versions were shipped as part of the Boost libraries, instead of the Standard Library, which shows there is nothing special.
But the core part of the language also includes some bits that are not simply function calls. In this case, the compiler authors need to devise a mapping of C source code text to CPU assembly code. That mapping is quite complex, especially for optimizing compilers. But this mapping can still be expressed in any language - there is no problem with a C compiler written in C , or a C compiler written in C. And for the same reason, a compiler for C 20 can easily be written in C 11. Sure, that C 20 compiler cannot use std::string_view
itself, useful as it might be, but it can still use a MyOwn::string_view
class instead.