[問題] stdio

看板C_and_CPP (C/C++)作者 (平凡)時間10年前 (2015/08/22 10:00), 10年前編輯推噓1(104)
留言5則, 2人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) devc 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): main.c內有include stdio.h 我又建了一個one.c 在裡面寫了一個函數test, test裡有用到printf run後有秀出printf的結果 我的問題是........ one.c為什麼不用include 就可以用printf呢? 及....不用在前面宣告函式一次(void test(void);) 編譯器沒報錯呢? 餵入的資料(Input): 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): 程式碼(Code):(請善用置底文網頁, 記得排版) //main.c #include <stdio.h> int main(int argc, char *argv[]) { test(); return 0; } ---------------- //one.c void test(void){ printf("1234"); } 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.25.178.63 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1440208800.A.292.html

08/22 10:10, , 1F
舊版 C 語言在沒宣告時預設為不檢查參數回傳 int
08/22 10:10, 1F

08/22 10:10, , 2F
printf 正好對得上所以沒事; test 原本也是這樣, 只是
08/22 10:10, 2F

08/22 10:11, , 3F
這裡沒回傳值所以沒什麼差
08/22 10:11, 3F
printf對得上是指? one.c沒有stdio.h 就可用printf是預設有stdio嗎? 您的意思是 如果int test(void),就會報錯?

08/22 11:46, , 4F
沒宣告直接使用時compiler會假設成 int printf(...)
08/22 11:46, 4F

08/22 11:47, , 5F
"剛好"和 stdio.h & libc 裡面的 printf 一樣
08/22 11:47, 5F
原來如此.........小懂了! ※ 編輯: GooLoo (114.25.178.63), 08/22/2015 11:52:37
文章代碼(AID): #1LrzUWAI (C_and_CPP)
文章代碼(AID): #1LrzUWAI (C_and_CPP)