LoginSignup
7
1

More than 5 years have passed since last update.

Ancient C探訪記:プリプロセッサ編

Posted at

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

(本投稿は Ancient C探訪記 シリーズの一部です。)

シリーズ最後の話題は「プリプロセッサ(Preprocessor)」を取り上げます。

Ancient Cのプリプロセッサ

defineマクロ

"C Reference Manual" §12.1 Token replacement から一部を引用します。Ancient Cでは、単純トークン置換を行うマクロ(macro)のみ利用可能です。関数形式マクロ(function-like macro)は存在しません。

A compiler-control line of the form

# define identifier token-string

(note: no trailing semicolon) causes the preprocessor to replace subsequent instances of the identifier with the given string of tokens (except within compiler control lines).

ファイルinclude

"C Reference Manual" §12.2 File inclusion から一部を引用します。Ancient Cではダブルクォーテーション("...")のみサポートします。山括弧(<...>)は記述できません。

To further exploit this technique when a large C program consists of several files, a compiler control line of the form

# include "filename"

results in the replacement of that line by the entire contents of the file filename.

標準規格との差分

Ancient Cのプリプロセッサには前述の2命令しかありません。シンプル!

標準C(ANSI C/C90)では#演算子、##演算子、条件付き取込み(Conditional inclusion)のdefined#if/#elif/#ifdef/#ifndef/#else/#endif、各種ディレクティブ#undef, #line, #error, #pragma、定義済みマクロ__DATE__, __TIME__が追加されています。


もっと "C Reference Manual" を読みこめば発見があるかもしれませんが、本シリーズはこの辺りでお開きとしたいと思います。

7
1
0

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
7
1