Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
C--
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|C-like programming language}} {{refimprove|date=April 2016}} {{Infobox programming language | name = C-- | logo = C-- logo.svg |logo caption = Unofficial logo for C-- which closely resembles the [[C++]] logo | paradigm = [[imperative programming|imperative]] | year = 1998 | typing = [[Type system|static]], [[Weak typing|weak]] | designer = [[Simon Peyton Jones]] and [[Norman Ramsey (computer scientist)|Norman Ramsey]] | influenced_by = [[C (programming language)|C]] | website = {{URL|www.cs.tufts.edu/~nr/c--/}} }} '''C--''' (pronounced ''C minus minus'') is a [[C (programming language)|C]]-like [[programming language]], designed to be generated mainly by [[compiler]]s for [[high-level language]]s 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 data|binary]] format.<ref name="april98" /><ref name="gc99" /> There are two main branches: * C--, the original branch, with the final version 2.0 released in May 2005<ref name="v2" /> * Cmm, the fork actively used as the [[intermediate representation]] (IR) in the [[Glasgow Haskell Compiler]] (GHC)<ref name="cmm-hs" /><ref name="llvm backend" /> ==Design== C-- is a "portable [[assembly language]]",<ref>{{Cite journal |last1=Oliva |first1=Dino |last2=Nordin |first2=T. |last3=Peyton Jones |first3=Simon |date=1997-01-01 |title=C-: A Portable Assembly Language |url=https://www.microsoft.com/en-us/research/publication/c-a-portable-assembly-language/ |journal=Proceedings of the 1997 Workshop on Implementing Functional Languages |language=en-US |via=Microsoft}}</ref> designed to ease the implementation of compilers that produce high-quality [[machine code]].<ref>{{Cite book |last1=Jones |first1=Simon Peyton |last2=Nordin |first2=Thomas |last3=Oliva |first3=Dino |date=1998 |editor-last=Clack |editor-first=Chris |editor2-last=Hammond |editor2-first=Kevin |editor3-last=Davie |editor3-first=Tony |chapter=C--: A portable assembly language |chapter-url=https://link.springer.com/chapter/10.1007/BFb0055421 |title=Implementation of Functional Languages |series=Lecture Notes in Computer Science |volume=1467 |language=en |location=Berlin, Heidelberg |publisher=Springer |pages=1β19 |doi=10.1007/BFb0055421 |isbn=978-3-540-68528-9}}</ref> This is done by delegating low-level [[Automatic programming|code-generation]] and [[program optimization]] to a C-- compiler. The language's [[Syntax (programming languages)|syntax]] borrows heavily from C while omitting or changing standard C features such as [[variadic function]]s, [[pointer (computer programming)|pointer]] syntax, and aspects of C's type system, because they hamper essential features of C-- and ease of code-generation. The name of the language is an in-joke, indicating that C-- is a reduced form of C, in the same way that "[[C++]]" was chosen to connote an improved version of C. (In C, <code>--</code> and <code>++</code> mean "decrement" and "increment", respectively.)<ref>{{Cite web |title=Increment And Decrement Operators In C With Precedence |url=https://unstop.com/blog/increment-and-decrement-operators-in-c |access-date=2024-06-20 |website=unstop.com}}</ref> Work on C-- began in the late 1990s. Since writing a custom [[Code generation (compiler)|code generator]] is a challenge in itself, and the compiler [[Compiler#Back end|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 is a poor choice for functional languages: it does not guarantee [[tail call|tail-call optimization]], or support accurate [[garbage collection (computer science)|garbage collection]] or efficient [[exception handling]]. C-- is a 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 a MSRA paper,<ref name=april98/> accompanied by a January 1999 paper on garbage collection.<ref name="gc99" /> A revised manual was posted in HTML form in May 1999.<ref name="c-- handbook" /> 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.<ref name="v2" /> ==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 array|bit-vector]]. However, bit-vector is a [[Type polymorphism|polymorphic]] type which comes in several widths, e.g. {{mono|bits8}}, {{mono|bits32}}, or {{mono|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 {{mono|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.<ref name=v2/>{{rp|28}} 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.<ref name="v2" />{{rp|10}} ==Example code== The following C-- code calculates the sum and product of integers 1 through n<ref>{{Citation | first1=Norman |last1=Ramsey |first2=Simon Peyton |last2=Jones |first3=Christian |last3=Lindig | date=2005-02-23 | title=The C-- Language Specification, version 2.0 (CVS Revision 1.128) | page=7 | url=https://www.cs.tufts.edu/~nr/c--/extern/man2.pdf | accessdate=2023-06-22 }}</ref> (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. <syntaxhighlight lang="c"> /* Tail recursion */ export sp; sp( bits32 n ) { jump sp_help( n, 1, 1 ); } sp_help( bits32 n, bits32 s, bits32 p ) { if n==1 { return( s, p ); } else { jump sp_help( n-1, s+n, p*n ); } } </syntaxhighlight> ==Implementations== The specification page of C-- lists a few implementations of C--. The "most actively developed" compiler, Quick C--, was abandoned in 2013.<ref name="tufts" /> ===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.<ref name="cmm-hs" /><ref>{{Cite web |title=5.10. GHC Backends β Glasgow Haskell Compiler 9.8.1 User's Guide |url=https://downloads.haskell.org/ghc/9.8.1/docs/users_guide/codegens.html#:~:text=5.10.-,GHC%20Backends,compiling%20it%20to%20executable%20code. |access-date=2024-06-20 |website=downloads.haskell.org}}</ref> GHC backends are responsible for further transforming C-- into executable code, via [[LLVM]] IR, slow C, or directly through the built-in native backend.<ref name="code generator" /><ref name="llvm">{{Cite web |date=August 25, 2019 |title=Opinion piece on GHC backends. |url=https://andreaspk.github.io/posts/2019-08-25-Opinion%20piece%20on%20GHC%20backends.html |access-date=2024-06-20 |website=andreaspk.github.io}}</ref><ref>{{Cite web |title=Using the Glasgow Haskell Compiler (GHC) |url=https://programmingdoer.com/ |access-date=2024-06-20 |website=ProgDoer}}</ref> 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.<ref name="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.<ref>{{Cite web |title=C-- Downloads |url=https://www.cs.tufts.edu/~nr/c--/code.html |access-date=2024-06-20 |website=www.cs.tufts.edu}}</ref> *'''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== {{Portal|Computer programming}} * [[BCPL]] * [[LLVM]] ==References== {{Reflist|refs= <ref name="april98">{{Cite journal|last1=Nordin|first1=Thomas|last2=Jones|first2=Simon Peyton|last3=Iglesias|first3=Pablo Nogueira|last4=Oliva|first4=Dino|date=1998-04-23|title=The Cβ Language Reference Manual|url=https://www.microsoft.com/en-us/research/publication/the-c-language-reference-manual/|journal=Microsoft|language=en-US}}</ref> <ref name="gc99">{{Cite journal|last1=Reig|first1=Fermin|last2=Ramsey|first2=Norman|last3=Jones|first3=Simon Peyton|date=1999-01-01|title=Cβ: a portable assembly language that supports garbage collection|pages=1β28 |url=https://www.microsoft.com/en-us/research/publication/portable-assembly-language-supports-garbage-collection/|journal=Microsoft|language=en-US}}</ref> <ref name="v2">{{cite web |last1=Ramsey|first1=Norman|last2=Jones|first2=Simon Peyton|title=The C-- Language Specification, Version 2.0 |url=https://www.cs.tufts.edu/~nr/c--/extern/man2.pdf |accessdate=11 December 2019}}</ref> <ref name="cmm-hs">[https://gitlab.haskell.org/ghc/ghc/wikis/commentary/rts/cmm GHC Commentary: What the hell is a .cmm file?]</ref> <ref name="llvm backend">{{cite web|title=An improved LLVM backend|date=April 2019 |url=https://ghc.haskell.org/trac/ghc/wiki/ImprovedLLVMBackend}}</ref> <ref name="code generator">[https://downloads.haskell.org/~ghc/7.8.3/docs/html/users_guide/code-generators.html GHC Backends]</ref> <ref name="debugging">[http://blog.ezyang.com/2011/06/debugging-compilers-with-optimization-fuel/ Debugging compilers with optimization fuel]</ref> <ref name="tufts">{{cite web |title=C-- Downloads |url=https://www.cs.tufts.edu/~nr/c--/code.html |website=www.cs.tufts.edu |accessdate=11 December 2019}}</ref> <ref name="c-- handbook">{{cite web |url=https://www.cs.tufts.edu/~nr/c--/extern/manual.html |last1=Nordin|first1=Thomas|last2=Jones|first2=Simon Peyton|last3=Iglesias|first3=Pablo Nogueira|last4=Oliva|first4=Dino|date=1999-05-23|title=The Cβ Language Reference Manual}}</ref> }} ==External links== * [https://web.archive.org/web/20080822062234/http://www.cminusminus.org/ Archive of old official website] (cminusminus.org) * [https://github.com/nrnrnr/qc-- Quick C-- code archive] (the reference implementation) [[Category:C programming language family]] [[Category:Compilers]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Citation
(
edit
)
Template:Cite book
(
edit
)
Template:Cite journal
(
edit
)
Template:Cite web
(
edit
)
Template:Infobox programming language
(
edit
)
Template:Mono
(
edit
)
Template:Portal
(
edit
)
Template:Refimprove
(
edit
)
Template:Reflist
(
edit
)
Template:Rp
(
edit
)
Template:Short description
(
edit
)