gcc -Dmacro=defn equivalent in VOS C compiler2007年05月25日 11時18分25秒

VOS C compiler は独自拡張が多く、かつどこにも書かれていない極秘機能が多くて困る。gcc や Sun C compiler はごく基本的なオプションは似ていることが多いので、見当が付けやすいが VOS C compiler はそうはいかない。


% cat three.c
#include 

int main()
{
    int i;

#ifdef DEBUG
    printf("%d\n", i);
#endif

    i = 3;
    printf("%d\n", i);
}

の様なコードがあったときに、わざわざコードを書き換えずに gcc -DDEBUG three.c の様にやりたい。VOS C compiler では、同じではないが類似的な事が出来るのを長いこと知らなかった。


c three
c: three.c
ready  12:09:38
bind three
Binder Statistics

Phase    Seconds     Paging   Disk I/O        CPU
pass1          0        243        267          0  12:09:41
pass2          0         12          0          0  12:09:41
map            0          8         94          0  12:09:41
TOTAL          0        263        361          0  12:09:41

Total bytes:                360802
Bytes per minute:         21648120
Bytes removed:                   0
Size of program:                92
ready  12:09:41
three
3
ready  12:09:52

さて、これがこのままコンパイルした時の動作である。


display debug.h

debug.h  07-05-24 12:10:13

#define DEBUG

c three.c debug.h
c: three.c
ready  12:10:29
bind three
Binder Statistics

Phase    Seconds     Paging   Disk I/O        CPU
pass1          0        243        356          0  12:10:32
pass2          0         12          0          0  12:10:32
map            0          8         94          0  12:10:32
TOTAL          0        263        450          0  12:10:32

Total bytes:                360906
Bytes per minute:         21654360
Bytes removed:                   0
Size of program:                92
ready  12:10:32
three
2145778248
3
ready  12:10:34

これを c three.c debug.h の様に、読み込みたいヘッダーファイルを並べると、そこから読み込まれるみたいだ。

おまけに少々実験してみた。


display four.c

four.c  07-05-24 12:14:45

int four()
{
    return 4;
}
ready  12:14:36
c four three
c: four.c

ERROR 1830 SEVERITY 3
Include file "three" not found.

c: Translation failed. four.c
ready  12:14:46
c four.c three.c
c: four.c
ready  12:14:57

二つ以上のファイルを並べるときには拡張子を省略できないらしい。


bind four
Binder Statistics

Phase    Seconds     Paging   Disk I/O        CPU
pass1          1        243        391          0  12:15:00
pass2          0         12          0          0  12:15:00
map            0          8         94          0  12:15:00
TOTAL          1        263        485          0  12:15:00

Total bytes:                361114
Bytes per minute:         21666840
Bytes removed:                   0
Size of program:                92
ready  12:15:00
four
3
ready  12:15:02

どうも、ヘッダファイルだけでなく、main 関数などもfour.obj に埋め込まれたようだ。c_preprocessor でも試してみたが、不正な引数だと言われ、二つのファイルを渡すことが出来なかった。

コメント

コメントをどうぞ

※メールアドレスとURLの入力は必須ではありません。 入力されたメールアドレスは記事に反映されず、ブログの管理者のみが参照できます。

※なお、送られたコメントはブログの管理者が確認するまで公開されません。

名前:
メールアドレス:
URL:
コメント:

トラックバック

このエントリのトラックバックURL: http://uyota.asablo.jp/blog/2007/05/25/1532437/tb

※なお、送られたトラックバックはブログの管理者が確認するまで公開されません。