2

コンパイラは、次のコード セグメントに対して次の警告を表示しました。修正してください。

if((tmp_n = (struct dot *)shmat(shm_net, NULL, 0)) == (int *) -1) { }
警告: 異なるポインタ型の比較にはキャストがありません [デフォルトで有効]

これは C プログラムであり、このコード セグメントは共有メモリ セグメントをポインタ **tmp_n にアタッチするためのもので、型は struct dot です。

struct dot {int weight; inttmv;};

4

2 に答える 2

3

これを試してみてください

if((tmp_n = (struct dot *)shmat(shm_net, NULL, 0)) == (void *) -1) { }

man-pageを見て、次のように述べています。

Return Value
On success shmat() returns the address of the attached shared memory segment; 
on error (void *) -1 is returned, and errno is set to indicate the cause of the error. 
于 2013-05-02T06:39:09.500 に答える
2

-1比較する変数と同じポインター型にキャストする必要があります。

if((tmp_n = (struct dot *)shmat(shm_net, NULL, 0)) == (struct dot *) -1) { }
于 2013-05-02T06:41:29.293 に答える