ArticleslgStudy

science

C--

C-- is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand C-- rather than just read about it. In short: C-- (conventionally written using hyphen-minuses but pronounced C minus minus) is a C-like programming language, designed to be generated mainly by compilers for high-level languages rather than written by human programmers. It was created by functional programming researchers Simon Peyton Jones and Norman Ramsey.

C-- — main illustration
C-- — illustration

Key takeaways

  • C-- belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect C-- to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of C-- from memory before moving on to harder problems.

Reference excerpt

C-- (conventionally written using hyphen-minuses but pronounced C minus minus) is a C-like programming language, designed to be generated mainly by compilers for high-level languages rather than written by human programmers. It was created by functional programming researchers Simon Peyton Jones and Norman Ramsey. Unlike many other intermediate languages, it is represented in plain ASCII text, not bytecode or another binary format. There are two main branches:

C--, the original branch, with the final version 2.0 released in May 2005 Cmm, the fork actively used as the intermediate representation (IR) in the Glasgow Haskell Compiler (GHC)

Design C-- is a "portable assembly language", designed to ease the implementation of compilers that produce high-quality machine code. This is done by delegating low-level code-generation and program optimization to a C-- compiler. The language's syntax borrows heavily from C while omitting or changing standard C features such as variadic functions, pointer syntax, and aspects of C's type system, because they are considered to hamper essential features of C-- and ease of code-generation. The name of the language is an in-joke, indicating that C-- is intended to be a reduced form of C, in the same way that "C++" was chosen to connote an improved version of C. (In C, -- and ++ mean "decrement" and "increment", respectively.) Work on C-- began in the late 1990s. Since writing a custom code generator is a challenge in itself, and the compiler backends available to researchers at that time were complex and poorly documented, several projects had written compilers which generated C code (for instance, the original Modula-3 compiler). However, C has various downsides for functional languages: it does not guarantee tail-call optimization, or support accurate garbage collection or efficient exception handling. C-- is intended as a supposedly tightly defined simpler alternative to C which supports all of these. Its most innovative feature is a run-time interface which allows writing of portable garbage collectors, exception handling systems and other run-time features which work with any C-- compiler. The first version of C-- was released in April 1998 as an MSRA paper, accompanied by a January 1999 paper on garbage collection. A revised manual was posted in HTML form in May 1999. Two sets of major changes proposed in 2000 by Norman Ramsey ("Proposed Changes") and Christian Lindig ("A New Grammar") led to C-- version 2, which was finalized around 2004 and officially released in 2005.

Type system The C-- type system is designed to reflect constraints imposed by hardware rather than conventions imposed by higher-level languages. A value stored in a register or memory may have only one type: bit-vector. However, bit-vector is a polymorphic type which comes in several widths, e.g. bits8, bits32, or bits64. A separate 32-or-64 bit family of floating-point types is supported. In addition to the bit-vector type, C-- provides a Boolean type bool, which can be computed by expressions and used for control flow but cannot be stored in a register or memory. As in an assembly language, any higher type discipline, such as distinctions between signed, unsigned, float, and pointer, is imposed by the C-- operators or other syntactic constructs. C-- is not type-checked, nor does it enforce or check the calling convention. C-- version 2 removes the distinction between bit-vector and floating-point types. These types can be annotated with a string "kind" tag to distinguish, among other things, a variable's integer vs float typing and its storage behavior (global or local). The former is useful on targets that have separate registers for integer and floating-point values. Special types for pointers and the native word were introduced, although they are mapped to a bit-vector with a target-dependent length.

Example code The following C-- code calculates the sum and product of integers 1 through n (n is received as an argument). It demonstrates two language features:

Procedures can return multiple results. Tail recursion is explicitly requested with the "jump" keyword.

Also, here's a simple "Hello World" example:

Implementations The specification page of C-- lists a few implementations of C--. The "most actively developed" compiler, Quick C--, was abandoned in 2013.

Haskell Some developers of C--, including Simon Peyton Jones, João Dias, and Norman Ramsey, work or have worked on GHC, whose development has led to extensions in the C-- language, forming the Cmm dialect which uses the C preprocessor for ergonomics. GHC backends are responsible for further transforming C-- into executable code, via LLVM IR, slow C, or directly through the built-in native backend. Despite the original intention, GHC does perform many of its generic optimizations on C--. As with other compiler IRs, the C-- representation can be dumped for debugging. Target-specific optimizations are performed later by the backend.

Processing systems As of 2018, most processing systems are not maintained, nor is their source code released.

Quick C-- is a compiler developed by The Quick C-- Team. It compiles version 2 of C-- code to Intel x86 Linux machine code. Compilation to machine code for other platforms is available as an experimental feature. Previously, Quick C-- was developed in parallel with the evolution of the C-- language specification, but the project was archived in 2019 on GitHub and development has ceased, though the source code is available there. cmmc is a C-- compiler implemented in the ML programming language by Fermin Reig. It generates machine code for Alpha, Sparc, and x86 architectures. Trampoline C-- Compiler is a C-- to C transpiler developed by Sergei Egorov in May 1999. It translates C-- code into C code, allowing it to be compiled using standard C compilers. The Oregon Graduate Institute's C-- compiler (OGI C-- Compiler) is the earliest prototype C-- compiler, developed in 1997 using the ML programming language. Maintenance of the OGI C-- Compiler was discontinued once development of Quick C-- began.

See also

BCPL LLVM C Intermediate Language

References

External links Archive of old official website (cminusminus.org) Quick C-- code archive (the reference implementation)

Illustrations

C-- illustration

Worked examples

Example 1 — a first encounter with C--

Start with the simplest possible case. Write down what C-- claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to C-- before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about C-- ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of C--

In research
C-- appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses C-- in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
C-- is common in secondary-school and first-year university syllabi. It links to neighbouring topics C programming language family, Compilers, so understanding it makes those chapters shorter.
In everyday life
Look for C-- outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “C--” →

How to study C-- in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what C-- means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain C-- out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is C-- in simple terms?

C-- (conventionally written using hyphen-minuses but pronounced C minus minus) is a C-like programming language, designed to be generated mainly by compilers for high-level languages rather than written by human programmers. It was created by functional programming researchers Simon Peyton Jones an…

Why does C-- matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study C--?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on C--.

Tags

  • C programming language family
  • Compilers

Keep exploring