From: Katsuyuki Komatsu Date: 2000-04-28T23:11:12+09:00 Subject: [ruby-list:22194] Re: #define const 小松です。 In the message of [ruby-list:22191] Re: #define const on 2000/4/28 21:44:35 toyofuku@juice.or.jp wrote: > > (PHSS_17507適用後はA.10.32.22) > > で-Ae -Oだと、変更前のsprintf.cのoptimizeでコンパイラが > > 落ちてたとか書いてあるな。 > > 落ちるというのはコンパイルエラーになるというの > ではなく、例えばコンパイラが core を吐いて落ちる > というようなことですか。 > ちょっとそれらしく sprintf.c を戻して試してみま > したが落とせませんでした。 core dumpじゃなくてinternal errorかなにかだったと思いますが、 ログ(というか自分宛に出して結局MLに流さなかったメール) には、落ちたとしか書いてないし、すでに1年近くたっているので 詳しいことは思い出せません。 申し訳ない。 自分宛に出したメール添付しておきますが、日付が、1999-05-19 だったので、ruby-1.3.3時代の話だったようです。 Message-Id: <199905191334.WAA01288@mail.sarion.co.jp> Subject: problematic prototype of sprintf.c To: komatsu@sarion.co.jp Date: Wed, 19 May 1999 22:34:01 +0900 From: Katsuyuki Komatsu To: ruby-dev@netlab.co.jp 小松です。 ANSI Cコンパイラでは、prototypeを宣言して後、実体の 関数定義をK&R形式で宣言した場合、char型の引数があると K&Rでchar型で受けた場合prototype的にはintとなるため 関数の引数の再定義とみなされてしまいます。 sprintf.cのfmt_setup()の第2引数で文句を言われました。 % cc -O -Xc -I. -I.. -I/usr/local/include -c ../sprintf.c "../sprintf.c", line 623: warning: identifier redeclared: fmt_setup current : function() returning void previous: function(pointer to char, char, int, int, int) returning void : "../sprintf.c", line 26 "../sprintf.c", line 625: warning: Prototype mismatch in arg 2 for function fmt_setup: function : old style declaration char promoted to int prototype: char % あと、HP-UX 10.20のPHSS_17507のパッチをあてる前の cc - HP92453-01 A.10.32.20 HP C Compiler (PHSS_17507適用後はA.10.32.22) で-Ae -Oだとoptimizeで失敗して、コンパイラが落ちて しまいました。 で、ANSI Cコンパイラに優しいコードにするため、 static void fmt_setup _((char*,char,int,int,int)); を static void fmt_setup _((char*,int,int,int,int)); にするか、sprintf.cの、 static void fmt_setup() を VALUE rb_f_sprintf() の定義より前に持って行ってもらってprototype宣言 #ifdef USE_CWGUSI static void fmt_setup(); #else static void fmt_setup _((char*,char,int,int,int)); #endif を削除していただけるとうれしいです。 / / / % uname -s -r SunOS 5.5.1 % cat proto.c void x(char *a, char b, int c, int d, int e); void y(char *a, char b, int c, int d, int e); void z(char *a, int b, int c, int d, int e); int main() { char *a = "", b = 0; int c = 0, d = 0, e = 0; x(a, b, c, d, e); y(a, b, c, d, e); z(a, b, c, d, e); return 0; } void x(a, b, c, d, e) char *a, b; int c, d, e; { } void y(char *a, char b, int c, int d, int e) { } void z(a, b, c, d, e) char *a, b; int c, d, e; { } % cc -Xc -c proto.c "proto.c", line 16: warning: identifier redeclared: x current : function() returning void previous: function(pointer to char, char, int, int, int) returning void : "proto.c", line 1 "proto.c", line 17: warning: Prototype mismatch in arg 2 for function x: function : old style declaration char promoted to int prototype: char % -- 小松克行 / Katsuyuki Komatsu