13
3

More than 5 years have passed since last update.

Ancient C探訪記:導入編

Last updated at Posted at 2017-12-09

おことわり: この記事では「1975年頃のC言語」仕様を解説します。2017年現在のC言語仕様とは異なるため、あなたのC言語ライフには役立たないことを予めご承知おきください。

この記事シリーズでは、プログラミング言語Cの生みの親 Dennis M. Ritchie 氏によって書かれた "C Reference Manual" を読み解き、現在のC言語仕様との違いをみていきます。そのタイトルが表す通り、オペレーティングシステム 6th Edition Unix(UNIX v6) に付属するC言語コンパイラのリファレンスマニュアルです。

Cの歴史と「Ancient C」

C言語の歴史上、この記事の対象は K&R C より古い1975年頃 に位置します。広く知られた通称も存在しないため、便宜上「Ancient C」と呼ぶことにします。

  • 1972年: (C言語が誕生)
  • 1975年: :star2:Ancient C」 "C Reference Manual"
  • 1978年: 通称「K&R C」書籍 "The C Programming Language 1st Ed."1
  • 1989年: 通称「ANSI C」標準規格 ANSI X3.159-1989
  • 1990年: 通称「C90」標準規格 ISO/IEC 9899:1990(ANSI Cと同じ)
  • 1999年: 通称「C99」標準規格 ISO/IEC 9899:1999
  • 2011年: 通称「C11」標準規格 ISO/IEC 9899:2011
  • 2017年: (C17 に向けた作業中...)

より詳細な歴史資料は、Ritchie氏自身の手による記事 The Development of the C Language を参照ください。

Ancient C言語仕様

冒頭で触れた通り "C Reference Manual" はあくまでリファレンスマニュアルであり、プログラミング言語を厳格に定義する言語仕様とは少し趣が違います。ただし、ANSI CやISO Cなどの標準規格に馴染みのある方2は感づいたかと思いますが、同リファレンスマニュアルの文章構造や書き方は現在の標準規格のそれと似た雰囲気になっています。

全 31 ページある "C Reference Manual" のうち、言語仕様に関する説明はわずか 19 ページです。最新のC言語標準規格 ISO/IEC 9899:2011 は 179 ページもありますから3、Ancient C 言語仕様は「プログラミング言語の仕様書ってどんな感じなんだろう」という方の入門用にも最適です!4

Ancient C目次

"C Reference Manual" より2ndレベルまでセクション名を引用します:5

 1. Introduction
 2. Lexical conventions
 2.1 Comments
 2.2 Identifiers (Names)
 2.3 Keywords
 2.3 Constants
 2.4 Strings
 3. Syntax notation
 4. What's in a Name?
 5. Objects and lvalues
 6. Conversions
 6.1 Characters and integers
 6.2 Float and double
 6.3 Float and double; integer and character
 6.4 Pointers and integers
 7. Expressions
 7.1 Primary expressions
 7.2 Unary operators
 7.3 Multiplicative operators
 7.4 Additive operators
 7.5 Shift operators
 7.6 Relational operators
 7.7 Equality operators
 7.8 expression & expression
 7.9 expression ^ expression
 7.11 expression && expression
 7.12 expression || expression
 7.13 expression ? expression : expression
 7.14 Assignment operators
 7.15 expression,expression
 8. Declarations
 8.1 Storage class specifiers
 8.2 Type specifiers
 8.3 Declarators
 8.4 Meaning of declarators
 8.5 Structure declarations
 9. Statements
 9.1 Expression statement
 9.2 Compound statement
 9.3 Conditional statement
 9.4 While statement
 9.5 Do statement
 9.6 For statement
 9.7 Switch statement
 9.8 Break statement
 9.9 Continue statement
 9.10 Return statement
 9.11 Goto statement
 9.12 Labelled statement
 9.13 Null statement
10. External definitions
10.1 External function definitions
10.2 External data definitions
11. Scope rules
11.1 Lexical scope
11.2 Scope of externals
12. Compiler control lines
12.1 Token replacement
12.2 File inclusion
13. Implicit declarations
14. Types revisited
14.1 Structures
14.2 Functions
14.3 Arrays, pointers, and subscripting
14.4 Labels
15. Constant expressions
16. Examples
16.1 Inner product
16.2 Tree and character processing
16.3 Formatted output
REFERENCES
APPENDIX 1 Syntax Summary
APPENDIX 2 Implementation Peculiarities

適当に明日以降につづきます。


  1. 「K&R」は同書著者 Dennis M. Ritchie, Brian Kernighan の頭文字です。 

  2. 「言語仕様を読む奴なんてそんなに居る訳ないだろ!」という至極当然なご指摘は甘受します。 

  3. ちなみに他プログラミング言語仕様だと、JavaScript(ECMA-262 6th Ed.) 290 ページ、C#(ECMA-334 4th Ed.) 440 ページ、C++(ISO/IEC 14882:2017) 446 ページ、Java(JLS 8th Ed.) 697 ページとなります。記述方法や定義範囲はそれぞれ異なるため単純比較はできませんが、普及しているプログラミング言語仕様の規模感は分かるかと思います。 

  4. 「だから言語仕様を読む奴なんてそんなに居る訳ないだろ!」以下略 

  5. 目次に 2.3 が2回登場するのは原文ママです。おそらく単純ミスでしょう。 

13
3
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
3