【◆QZaw55cn4c 隔離】C/C++の問題を片付けますat TECH
【◆QZaw55cn4c 隔離】C/C++の問題を片付けます - 暇つぶし2ch284:デフォルトの名無しさん
10/12/03 10:22:17
mingwらしいから多分gcc3.4ぐらいを想定すべきだよな

285:デフォルトの名無しさん
10/12/03 12:22:35
>>282
なんか shall って弱くねぇか?「としても良い」くらいにしか読めないんだけど
別に bcc に限らず void* に対して加減算するのは変だってのは一般的感覚に思えるんだけどねぇ
実際にそんなコード書いたらレビューで叩かれるし....

286:デフォルトの名無しさん
10/12/03 12:39:35
>>285
JIS-X3010には同じ箇所は

voidへのポインタは、文字列型への表現及び同じ境界調整要求を「持たなければならない」。

とあるね。
「としても良い」とは訳してないようだ。

287:デフォルトの名無しさん
10/12/03 13:03:34
>>286
単に >>282 を見ての意見だから JIS がどう訳したなんて知らんよ、この業界は誤訳も多いしね

少なくとも void* に加減算なんてタココードは普通の現場では許されないって話は確かだよ
bcc がその規約から外れてるのはこれを一般的と解釈しての結果だろうな

288:デフォルトの名無しさん
10/12/03 13:37:26
>282
C89でもそうなっていったわ
3.1.2.5 Types
A pointer to void shall have the same representation and alignment
requirements as a pointer to a character type. Other pointer types
need not have the same representation or alignment requirements.
まさかのキャラポ、まぁ感覚的には気持ち悪いが規格が正義だからいいや

C99ではさらに、引数、戻り値、共用体のメンバにおいてそれが暗に行われるっぽいね
これ以上はガチスレ行った方が良さそうだ

char*と同じ表現(?)と境界を満たすのはvoid*が無かったころの関数と互換性を保つためなのだろうか

289:デフォルトの名無しさん
10/12/03 13:41:59
まあ、1バイトの型の代表だからじゃね? memsetも、

 void *memset(void *s, int c, size_t n);
 sは、unsigned char *型にキャストされ、cは、unsigned char型にキャストされる。

とある。

290:デフォルトの名無しさん
10/12/03 14:02:22
>288
なんか書いてないかなぁと思ってRationale読んだら書いてあった
3.1.2.5 Types
A pointer to void must have the same represen-
tation and alignment as a pointer to character; the intent of this rule is to allow
existing programs which call library functions (such as memcpy and free) to con-
tinue to work.
やっぱりそうだったか

291:デフォルトの名無しさん
10/12/03 15:08:09
ちなみにC++では規則はかなり異なっていて

§3.9.2
4 Objects of cv-qualified (3.9.3) or cv-unqualified type void* (pointer to void),
can be used to point to objects of unknown type. A void* shall be able to hold
any object pointer. A cv-qualified or cvunqualified (3.9.3) void* shall have the same
representation and alignment requirements as a cv-qualified or cv-unqualified char*.

はいいのだが

§C.1.2.4.10
Change: Converting void* to a pointer-to-object type requires casting
char a[10];
void *b=a;
void foo() {
char *c=b;
}
ISO C will accept this usage of pointer to void being assigned to a pointer to object type.
C + + will not.
Rationale: C + + tries harder than C to enforce compile-time type safety.
Effect on original feature: Deletion of semantically well-defined feature.
Difficulty of converting: Could be automated. Violations will be diagnosed by the
C++ translator. The fix is to add a cast For example:
char *c = (char *) b;
How widely used: This is fairly widely used but it is good programming practice to add
the cast when assigning pointer-to-void to pointer-to-object. Some ISO C translators
will give a warning if the cast is not used.

などなどいろいろ制限が強くなっている

292:デフォルトの名無しさん
10/12/03 15:30:29
sizeof(void)ってw

293:デフォルトの名無しさん
10/12/03 15:58:55
個人的な主観で説明する人も増えて、アスペルガーっぽい融通の利かない人も
目立ちますね。最終的には「お前がそう思うんならそうなんだろう、お前ん中ではな」
って言われて一蹴されますよ。

294:デフォルトの名無しさん
10/12/03 16:14:57
>>293
規格の話をしてるんだが、なぜそこでアスペルガーの話が出てくるんだ?馬鹿かお前?
規格は規格だ
それ以上でもそれ以下でもない
主観が入る余地もない

295:デフォルトの名無しさん
10/12/03 16:59:19
話についていけないけど、とにかく他人を煽りたい

296:デフォルトの名無しさん
10/12/03 17:24:40
>>295
とにかく他人を煽りたい奴は自己愛性人格障害と考えられます
現在の精神医学では不治の病です
最も人に嫌われる精神障害です

297:デフォルトの名無しさん
10/12/03 19:57:26
printf("%d\n",sizeof(void));
してみたら
 gcc(v3.2.2 , v3.4.5 , v4.3.4)実行結果 1
 cl(Version 12.00.8804)実行結果 0
 bcc32 コンパイルエラー
 CC38H コンパイルエラー (H8用Cコンパイラ)
となった。まともに動くのは gcc のみかな。

298:void* = void* + size_t
10/12/03 19:59:33
linux-2.6.37-rc4
/include/linux/relay.h の30行目

/*
* Per-cpu relay channel buffer
*/
struct rchan_buf
{
    void *start;          /* start of channel buffer */


linux-2.6.37-rc4
/karnel/relay.c の1090行目

/*
*   subbuf_read_actor - read up to one subbuf's worth of data
*/
static int subbuf_read_actor(size_t read_start,
               struct rchan_buf *buf,
               size_t avail,
               read_descriptor_t *desc,
               read_actor_t actor)
{
    void *from;
    int ret = 0;

    from = buf->start + read_start;



299:デフォルトの名無しさん
10/12/05 22:30:17
テスト

300:デフォルトの名無しさん
10/12/05 22:33:57
テスト

301:デフォルトの名無しさん
10/12/05 23:48:48
テスト
Σ(☉◇☉)

302:デフォルトの名無しさん
10/12/05 23:51:19
学期末テストですか?

303:デフォルトの名無しさん
10/12/06 00:19:59
test

304:デフォルトの名無しさん
10/12/06 09:38:05
ポスト


最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch