<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://halfgeek.org/wiki/index.php?action=history&amp;feed=atom&amp;title=Cx_%28pedantic_C-language_variants%29</id>
	<title>Cx (pedantic C-language variants) - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://halfgeek.org/wiki/index.php?action=history&amp;feed=atom&amp;title=Cx_%28pedantic_C-language_variants%29"/>
	<link rel="alternate" type="text/html" href="https://halfgeek.org/wiki/index.php?title=Cx_(pedantic_C-language_variants)&amp;action=history"/>
	<updated>2026-05-28T12:16:00Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.0</generator>
	<entry>
		<id>https://halfgeek.org/wiki/index.php?title=Cx_(pedantic_C-language_variants)&amp;diff=284&amp;oldid=prev</id>
		<title>161.253.47.104 at 09:34, 26 October 2005</title>
		<link rel="alternate" type="text/html" href="https://halfgeek.org/wiki/index.php?title=Cx_(pedantic_C-language_variants)&amp;diff=284&amp;oldid=prev"/>
		<updated>2005-10-26T09:34:29Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Programming Language Concepts (book)]] creates variants of C called C1, C2, C3, C4, and C5 entirely for instructional purposes.  The examples are from the book.  [[SIMPLESEM]] listings are given line numbers that should be omitted in reality. Stray ?, +, * correspond to their meanings in Perl regexps.&lt;br /&gt;
&lt;br /&gt;
=C1=&lt;br /&gt;
&lt;br /&gt;
A lexical variant of a subset of C.&lt;br /&gt;
&lt;br /&gt;
==Features==&lt;br /&gt;
&lt;br /&gt;
* Simple types&lt;br /&gt;
** No dynamic memory&lt;br /&gt;
** All primitive types&lt;br /&gt;
** Fixed-size arrays&lt;br /&gt;
** Structures&lt;br /&gt;
* Simple statements&lt;br /&gt;
** get(...) is a builtin to read stdin (e.g., &amp;#039;&amp;#039;get(i,j)&amp;#039;&amp;#039;)&lt;br /&gt;
** print(...) is a builtin to write stdout&lt;br /&gt;
* No functions&lt;br /&gt;
** Entire program is within main()&lt;br /&gt;
&lt;br /&gt;
==Sample==&lt;br /&gt;
&lt;br /&gt;
 main()&lt;br /&gt;
 {&lt;br /&gt;
   int i, j;&lt;br /&gt;
   get(i, j);&lt;br /&gt;
   while(i != j)&lt;br /&gt;
     if(i &amp;gt; j)&lt;br /&gt;
       i -= j;&lt;br /&gt;
     else&lt;br /&gt;
       j -= i;&lt;br /&gt;
   print(i);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Equivalent SIMPLESEM===&lt;br /&gt;
&lt;br /&gt;
 0: set 0, read&lt;br /&gt;
 1: set 1, read&lt;br /&gt;
 2: jumpt 8, D[0] = D[1]&lt;br /&gt;
 3: jumpt 6, D[0] &amp;lt;= D[1]&lt;br /&gt;
 4: set 0, D[0] - D[1]&lt;br /&gt;
 5: jump 7&lt;br /&gt;
 6: set 1, D[1] - D[0]&lt;br /&gt;
 7: jump 2&lt;br /&gt;
 8: set write, D[0]&lt;br /&gt;
 9: halt&lt;br /&gt;
&lt;br /&gt;
where D[0] and D[1] are i and j, respectively.&lt;br /&gt;
&lt;br /&gt;
=C2=&lt;br /&gt;
&lt;br /&gt;
C1, but with simple routines.  Note that, unlike in actual C, function definitions (except main()) are suffixed with a &amp;#039;&amp;#039;;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
==New features==&lt;br /&gt;
&lt;br /&gt;
* Simple routines&lt;br /&gt;
** Routines can declare their own data&lt;br /&gt;
** May access local and (unredeclared) global variables&lt;br /&gt;
** No parameters&lt;br /&gt;
** No return values&lt;br /&gt;
** Routines &amp;#039;&amp;#039;may&amp;#039;&amp;#039; call other routines&lt;br /&gt;
** Recursion &amp;#039;&amp;#039;not&amp;#039;&amp;#039; allowed&lt;br /&gt;
*** A routine may not call itself (direct recursion)&lt;br /&gt;
*** A routine may not call (a routine that calls)+ it (indirect recursion)&lt;br /&gt;
** Nesting &amp;#039;&amp;#039;not&amp;#039;&amp;#039; allowed&lt;br /&gt;
&lt;br /&gt;
==Compiling into SIMPLESEM==&lt;br /&gt;
&lt;br /&gt;
The assumptions in C1 and C2 allow the size of each unit&amp;#039;s activation record (AR) (that is, the layout of D for each routine in SIMPLESEM) to be determined at compile time, and variables can be statically allocated (in absence of nesting, recursion, and dynamic variables, all variables can map permanently to indices of D at compile time).  The rules of static allocation are exactly as if all local variables were declared with the static keyword.&lt;br /&gt;
&lt;br /&gt;
The first location in each AR (except main) is reserved for the return pointer for that function.  The calling function copies the position number one after the jump to the return pointer before jumping:&lt;br /&gt;
&lt;br /&gt;
 14: set 6, 16&lt;br /&gt;
 15: jump 100&lt;br /&gt;
&lt;br /&gt;
Note that in C2, this is set to a constant (16) and not the more apparently sensible meta-location (ip+1).&lt;br /&gt;
&lt;br /&gt;
Then, the corresponding routine ends by jumping back using the pointer.&lt;br /&gt;
&lt;br /&gt;
 jump D[6]&lt;br /&gt;
&lt;br /&gt;
==Layout==&lt;br /&gt;
&lt;br /&gt;
* Global declaration*&lt;br /&gt;
* (Routine definition|routing declaration)*&lt;br /&gt;
* main(), which is a routine that is automatically executed and cannot be explicitly called&lt;br /&gt;
&lt;br /&gt;
==Sample==&lt;br /&gt;
&lt;br /&gt;
 int i = 1, j = 2, k = 3;&lt;br /&gt;
 alpha()&lt;br /&gt;
 {&lt;br /&gt;
   int i = 4, l = 5;&lt;br /&gt;
   ...&lt;br /&gt;
   i += k + l;&lt;br /&gt;
   ...&lt;br /&gt;
 };&lt;br /&gt;
 beta()&lt;br /&gt;
 {&lt;br /&gt;
   int k = 6;&lt;br /&gt;
   ...&lt;br /&gt;
   i = j + k;&lt;br /&gt;
   alpha();&lt;br /&gt;
   ...&lt;br /&gt;
 }&lt;br /&gt;
 main()&lt;br /&gt;
 {&lt;br /&gt;
   ...&lt;br /&gt;
   beta();&lt;br /&gt;
   ...&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=C2&amp;#039;=&lt;br /&gt;
&lt;br /&gt;
C2, but with support for incremental/separate compilation.  The extern keyword is used to declare externals:&lt;br /&gt;
&lt;br /&gt;
 extern beta();&lt;br /&gt;
 extern int k;&lt;br /&gt;
&lt;br /&gt;
As program files are compiled individually, addresses are given relative to the beginning of the code block (in C) or the AR (in D), and resolved later by a linker.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
* [[Programming Language Concepts (book)]]&lt;br /&gt;
&lt;br /&gt;
=See also=&lt;br /&gt;
&lt;br /&gt;
* [[GWU CSCI 169]]&lt;/div&gt;</summary>
		<author><name>161.253.47.104</name></author>
		
	</entry>
</feed>