5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ヘッダーをちょいワル系で使う

Last updated at Posted at 2013-04-16

ヘッダーのインクルードとは、単なる「ファイルの内容を挿入」することに他なりません。
例えば、

hoge.hファイルに1行以下のコードがあったとします。

NSLog(@"hoge");

そして、mainのプログラムでこう書きます。

# import <Foundation.h>

int main()
{
    #include "hoge.h"
    return 0;
}

するとこれはコンパイル時には

# import <Foundation.h>

int main()
{
    NSLog(@"hoge");
    return 0;
}

と展開されますね。
つまり結局はマクロなのですね。

これを利用すると、普通の関数呼び出しやクラス等でのコードの再利用とは、
スケールの違ったありえないレベルでコードの使い回しが可能になります。
アスペクト指向なんて目じゃないです。
こういった無茶ができるのがC系統言語のいいところだと思います。

え? あまりお行儀よくないって?
ええ、まったくおっしゃる通りでございます。
ご利用は計画的に。

5
4
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
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?