看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) Linux OpenSUSE and GCC Complier 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 我宣告了一個Unsigned Char *a,採用動態配置記憶體的方式讓它指向2 bytes的空間, 接著轉型成 Unsigned Int ,使用<<向左移動4bits,再轉回來Unsigned Char 餵入的資料(Input): 程式碼(Code):(請善用置底文網頁, 記得排版) unsigned char *a; a = (unsigned char *)malloc(sizeof(char) * 2); a = '0x1'; /**原始程式碼是讀取Binary檔案**/ a = (unsigned char)((unsigned int) a << 4); 補充說明(Supplement): 這樣沒有錯誤,但是會有警告,想請問板上的鄉民,這樣寫有什麼不妥的地方嗎? 警告訊息如下,出現在<<的那行: assignment makes pointer from integer without a cast -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.221.67.235
james732:a = '0x1'; 是不是應該要寫成 *a ? 04/01 11:17
james732:下面那行也一樣,a = (... <<4); 應該是 *a 04/01 11:18
shiengchyi:*a = .... <---這樣嗎? 04/01 11:18
james732:try it. 記得第一個 malloc 不可以加 * 04/01 11:19
shiengchyi:恩恩 感謝 ^^ 04/01 11:20
※ 編輯: shiengchyi 來自: 61.221.67.235 (04/01 11:21)
shiengchyi:解決了 ^^/ 04/01 11:39