Forums: Help (Thread #4077)

kcre_mpf.cについて (2003-12-29 15:37 by Anonymous #7253)

毎度お世話になっております。nabeでございます。
CVSでソースをダウンロードできるようになり、
早速カーネルライブラリを構築したところ、
kcre_mpf.cでコンパイルエラーが出ました。
ターゲットは前回同様SH-2で、環境はルネサス純正
HEW3です。

エラー内容・・・
Phase SH C/C++ Compiler starting
C:\HOS_CVS\hos_sjis\hos-v4\src\kernel\mpf\kcre_mpf.c
C:\HOS_CVS\hos_sjis\hos-v4\src\kernel\mpf\kcre_mpf.c(92) : C2215 (E) Illegal type for "+"
C:\HOS_CVS\hos_sjis\hos-v4\src\kernel\mpf\kcre_mpf.c(93) : C2224 (E) Illegal type for assign
Phase SH C/C++ Compiler finished

対象の部分は・・・
/* ブロックの初期化 */
for ( i = 0; i < mpfcb_rom->blkcnt - 1; i++ )
{
★ *(VP *)mpf = (VP)(mpf + mpfcb_rom->blksz); ←ここと
★ mpf += mpfcb_rom->blksz;
} ←ここです。
*(VP *)mpf = NULL; /* 最終ブロック */

/* 管理テーブルへ追加 */
KERNEL_MPFID_TO_MPFCB_RAM(mpfid) = mpfcb_ram;

ルネサス純正コンパイラでは足し算が
1.両方が算術型  または
2.片方が算術型+片方がポインタ型
でないと、上記のエラーが発生するらしいです。
GCCとかではもしかしてOKなのですかね?
今はHEWしか手持ちがないので、試せないのですが、
情報として挙げておきます。解決策等あればご教授
ください。

以上、よろしくお願いいたします。

Reply to #7253×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: kcre_mpf.cについて (2003-12-29 15:38 by Anonymous #7254)

すみません矢印ずれてました。
対象の部分は・・・
/* ブロックの初期化 */
for ( i = 0; i < mpfcb_rom->blkcnt - 1; i++ )
{
★ *(VP *)mpf = (VP)(mpf + mpfcb_rom->blksz); ←ここと
★ mpf += mpfcb_rom->blksz; ←ここです。
} 
*(VP *)mpf = NULL; /* 最終ブロック */

/* 管理テーブルへ追加 */
KERNEL_MPFID_TO_MPFCB_RAM(mpfid) = mpfcb_ram;
Reply to #7253

Reply to #7254×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: kcre_mpf.cについて (2003-12-29 15:44 by ryuz #7255)

お世話になります。Ryuzです。

エラーにならないほうがおかしいですね。
voidポインタに整数足しちゃいけないです。

直します。ごめんなさい。
# なんで、gccだと通ったのだろう.. (^^;;
Reply to #7254

Reply to #7255×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: kcre_mpf.cについて (2003-12-29 15:53 by Anonymous #7256)

早速の回答ありがとうございます。
やっぱりvoidポインタの足し算ってキャストするか
なんかしないとダメってことなんですよね?
この辺は初心者にわかりづらいところで(^^ゞ
GCCでは通っているのですか?それはまた・・・
GCCはどんな風に解決しているのか一抹の不安になったり・・・
Reply to #7255

Reply to #7256×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: kcre_mpf.cについて (2003-12-30 12:04 by ryuz #7263)

 お世話になります。Ryuzです。
# 遅レスですが...

> やっぱりvoidポインタの足し算ってキャストするか
> なんかしないとダメってことなんですよね?

ANSI-C言語的には必須ですね。

> GCCでは通っているのですか?それはまた・・・
> GCCはどんな風に解決しているのか一抹の不安になったり・・・

一応試した見たところバイトで処理してるようですね。

 しかし、この辺がgccの良いところであり悪いところ
なんですよね。 (^^;;
 gccは数あるコンパイラの中でも独自拡張が大好きな
部類に入ってると個人的には思ってます。
 最近(といっても結構になるのかな?)Interface誌で
特集あって知ったのですが、gcc独自機能の多さに
驚きました。
 まあC99とか新しい規格も「gccが源流じゃないの?」
というものも多く、時代の牽引をしてきた面もあります
し、今回のようにうっかり移植性を落としてしまうことも
ありますから一長一短なのかなと。

 「あるものは使え!」派の人もいらっしゃいますが、
やはり、ルールは知っておいた上で「いつルールを
破るべきか」というポイントを抑えておかないと
思わぬ罠にかかっちゃいますね。
 うーん、難しい... 勉強せねば (^^;;
Reply to #7256

Reply to #7263×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: kcre_mpf.cについて (2004-01-01 01:24 by m-arai #7270)

ちょっと山に登ってまして、話題に乗り遅れてしまっていたのですが…

>> やっぱりvoidポインタの足し算ってキャストするか
>> なんかしないとダメってことなんですよね?
>
>ANSI-C言語的には必須ですね。
>
>> GCCでは通っているのですか?それはまた・・・
>> GCCはどんな風に解決しているのか一抹の不安になったり・・・
>
>一応試した見たところバイトで処理してるようですね。

なんですが、ISO/IEC 9899:1999では、

§6.2.5 p36
A pointer to void shall have the same representation
and alignment requirements as a pointer to a character type.

などとなってたりするので、バイトとして扱うのもあながち変じゃないのではないかなぁ~などと思ったりも…。
#((( ;゚Д゚)) ご、誤読してないかな、私?

いや、voidの意味を考えると、void *の演算って
どうなんだという方が正しいし、筋も通っているようには
思いますが。

と、無理から蒸し返すのも、↓だけではちょっとポスト
しにくいからです。(^^;

あけましておめでとうございます。
Reply to #7263

Reply to #7270×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: kcre_mpf.cについて (2004-01-01 02:26 by ryuz #7271)

 あけましておめでとうございます。
 Ryuzです。

> A pointer to void shall have the same representation
> and alignment requirements as a pointer to a character type.

 ぎゃ、こんな記述があったとは...
 ISOってANSI互換でしたよね、確か。

 自信を持って不可の記憶があったので調べずに
書いてしまいました。申し訳ない。
 いったいどこで読んだのだろう...

 ANSIの正確な規約書は入手してないのですが(有料
でしたよね確か?)、ちょっとショッキングですね。

 しかし、なぜANSI準拠をうたうコンパイラでエラーに
なるのかも疑問だったりして...

 調べてるんですがなかなか明確な答えにたどり
着けないです。
 ANSI規約は個人的に押さえておきたい部分なので
すっごく気になります。
# 規格書買ったほうがいいのかなぁ (^^;

 ちょい調べてみますね。

 なにわともあれ、今年も皆様にとって良い年で
ありますように(^^)

 今年もよろしくお願いします。

Reply to #7270

Reply to #7271×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: kcre_mpf.cについて (2004-01-01 02:50 by ryuz #7272)

 お世話になります。Ryuzです。

> なんですが、ISO/IEC 9899:1999では、

ひょっとして 1999年だと C99規格なのでは?
ANSIX3-159(1989年)との互換性だとISOだとどれに
なるのでしょう?
 おんなじ番号で ANNEX が付いてたりするから混乱
するんですよね...
# って、ITU-T でよくはまるぼくちゃん (^^;;

 ぐぐってるんですが、なかなかうまくヒットしてく
れない...

 プロの降臨を待つしかないのかな (^^;;
 情報希望です。
Reply to #7271

Reply to #7272×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: kcre_mpf.cについて (2004-01-01 07:25 by hamayan #7273)

Cのバージョンに関係するなら、

ルネサスのコンパイラの最新版ver.8でもC99対応とは言っていないですね。
一部C99の機能、例えばlong longとかはサポート始めていますが。

最新の機能面とか、検証の深さとか、バグへの対応で言うと、GCCに部が有ると思えます。
ルネサスの場合、未だにver.7のバグが出て、ぎゃ!って言わせてくれますから。もっとも、変ちくりんなバグが多いので、実害が少ないのですが。

GCCの場合、FREEでオープンで有る事が、ユーザーの意識レベルを上げていて、それがいい方向に廻っているんでしょうね。例えばm-araiさん等が強力にサポートされていますから。
Reply to #7272

Reply to #7273×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

規格… (2004-01-01 11:30 by m-arai #7275)

おそらくC99だと思います。

なかなか規格と言う奴は色々で良く分かりません。
どこかにまとまってませんかね。日本語で。(^^;
Reply to #7272

Reply to #7275×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: 規格… (2004-01-03 09:42 by Anonymous #7282)

スレ立てたnabeです。
あけましておめでとうございます。
知らぬ間にスレッドが伸びてまして・・・
迅速な対応ありがとうございます。

無い頭を絞って考えましたが、個人的には
今回のようなvoidに演算をかます場合は
エラーが出てくれたほうが助かります。
インクリメントなんかの場合は、charとして
バイトで動作しても問題ないんでしょうが、
この手のものがバグとして出た場合、結構
探すのにやっかいな気がしたりします。
規格がそのように言っているなら仕方ない
ですが。。。。
教科書的にはキャストの乱用は好ましくない
ようですが、私は「void」=キャストと認識
しているので、ルネサス派に1票。。。

これからもよろしくお願いいたします。
ありがとうございました。
Reply to #7275

Reply to #7282×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: kcre_mpf.cについて (2004-01-10 02:38 by h-iwamoto #7361)

足し算の方から読み進めていくと

6.5.6 p2
For addition, either both operands shall have arithmetic type, or one operand shall be a
pointer to an object type and the other shall have integer type.

となっているのがみつかります。
次に「an object type」にvoidが含まれているか
が問題になるので「object type」の説明を探します。

6.2.5 p1
Types
are partitioned into object types (types that fully describe objects), function types (types
that describe functions), and incomplete types (types that describe objects but lack
information needed to determine their sizes).

6.2.5 p19
The void type comprises an empty set of values; it is an incomplete type that cannot be
completed.

voidは「incomplete types」なので「object type」ではないようです。
したがってvoidへのポインタと整数の足し算は認めれないことになります。
Reply to #7270

Reply to #7361×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: kcre_mpf.cについて (2004-01-10 10:19 by m-arai #7362)

…ふうむ。やはりそうなりますか。議論としてはもっと
先に終わってる訳ですね。

結局のところ、あの文に脚注39)に示される
>The same representation and alignment requirements
>are meant to imply interchangeability as
>arguments to functions, return values from
>functions, and members of unions.
範囲以外の解釈を読もうとすること自体、元より無理が...

混乱させて済みません>ALL
Reply to #7361

Reply to #7362×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: kcre_mpf.cについて (2003-12-29 15:55 by ryuz #7257)

とりあえず、修正してコミットしました。
# VC++も抜けたのだろうか...
# にわかに信じられない (^^;;;

個人的にはBC++とか、構文チェクやワーニング
厳しくて好きなんですけどね。
 lint とか含めて、ちょっとこの手のチェック
環境充実考えてみます。
 今HDD入れ替えてPC空っぽなんですよ。 ちょうど
cygwin上で gcc のmakeが終わったタイミングでした。
# ある意味ナイスタイミングw
Reply to #7255

Reply to #7257×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: kcre_mpf.cについて (2003-12-29 17:53 by hamayan #7259)

ああ、私のところでもそうだったので、

/* ブロックの初期化 */
for ( i = 0; i < mpfcb_rom->blkcnt - 1; i++ )
{
*(VP *)mpf = (VP)((char *)mpf + mpfcb_rom->blksz);
mpf = (char *)mpf + mpfcb_rom->blksz;
}

とやって凌いでいました。
報告遅れていてすいません。

ところでRyuz氏はようやく正月休み?
Reply to #7254

Reply to #7259×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: kcre_mpf.cについて (2003-12-29 19:55 by ryuz #7260)

 お世話になります。Ryuzです。
# 何とかお正月が迎えられる予定です(多分w)

 とりあえずVC++でmakeかけてみたんですが、修正前の
リビジョンだとエラー食いますね。
 VC++のプロジェクトファイルも文字コードと
エラーチェックレベルちょいいじりました。

 別件で「使ってない変数を定義してます」も
食らったのでこれも修正しておきました。

 最近、lint や gmake、makedpend とかUNIXな
技を少し覚えたので使ってみたいころあい
だったりしてw
 しかし、UNUX系は gmake に統一されていて
うらやましいです。
 Win系はメーカーごとにmakeの文法ぜんぜん
違うから汎用性考えると今みたいにmakefile量産に
なってしまうし...

 gcc系は見直してもいいのかも(と、今更刺さ
れそうな事を書いてみる)
# わー、ごめんなさい1年前に半ばwin文化を
# 押し付けたの私です m(_ _)m

 で、毎年、盆と正月しか活動してない気がするん
ですが、なんか私のお仕事ありますか? (^^;;
Reply to #7259

Reply to #7260×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: kcre_mpf.cについて (2003-12-29 21:33 by hamayan #7261)

いやいや、この次期位はゆっくり休んでもらわないと・・・
Reply to #7260

Reply to #7261×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login