[問題] volatile void cast

看板C_and_CPP作者 (蛇王)時間11年前 (2012/10/27 01:26), 編輯推噓2(205)
留言7則, 4人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) GCC 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) aio.h 問題(Question): aio.h 的 struct aiocb 之中有個 volatile void *aio_buf; 我這樣寫: int* buffer = new int[100]; unsigned long long int sum(0); ... cb.aio_buf = buffer; ... for(int i=0; i<100; i++) sum+ = (unsigned long long int)cb.aio_buf[i]; //這行出現錯誤 ... 錯誤結果(Wrong Output): code.cpp: In function 'int main()': code.cpp:46: error: expected primary-expression before '=' token code.cpp:46: error: pointer of type 'void *' used in arithmetic code.cpp:46: error: 'volatile void*' is not a pointer-to-object type 程式碼(Code):(請善用置底文網頁, 記得排版) http://ppt.cc/BVnj 補充說明(Supplement): http://ppt.cc/5C8d (aio.h) -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.124.107.50

10/27 02:38, , 1F
因為你把 += 兩個人給拆散了
10/27 02:38, 1F

10/27 12:16, , 2F
XD
10/27 12:16, 2F
感謝XD 不過這樣只改進了第一個error 剩下兩個仍舊 ※ 編輯: morris0117 來自: 59.124.107.50 (10/27 13:07)

10/27 13:17, , 3F
aio_buf 是 void *, 編譯器不知道元素大小, subscript 運
10/27 13:17, 3F

10/27 13:18, , 4F
算子無法用; 要馬你先轉型成 int * 要馬用 sizeof 配合指
10/27 13:18, 4F

10/27 13:19, , 5F
標運算
10/27 13:19, 5F

10/27 13:20, , 6F
(話說我剛用 clang 錯誤訊息就很明顯, gcc 這誰看得懂)
10/27 13:20, 6F

10/30 10:44, , 7F
我不知道
10/30 10:44, 7F
文章代碼(AID): #1GYiUrVy (C_and_CPP)