由printf引發的runtime error

N年沒碰printf這玩意了,今兒個遇上個悲劇問題

整個悲劇可以精簡爲一句代碼的事

printf("%f", 4/2);

運行就有悲劇出來了

runtime error R6002

- floating point not loaded

 

貌似沒見過這種錯誤

翻下MSDN查看R6002

 

Error Message

floating-point support not loaded

The necessary floating-point library was not linked.

To fix by checking the following possible causes

  1. The program was compiled or linked with an option, such as /FPi87, that requires a coprocessor, but the program was run on a machine that did not have a coprocessor installed.

  2. A format string for a printf_s or scanf_s function contained a floating-point format specification and the program did not contain any floating-point values or variables.

  3. The compiler minimizes a program's size by loading floating-point support only when necessary. The compiler cannot detect floating-point format specifications in format strings, so it does not load the necessary floating-point routines.

  4. Use a floating-point argument to correspond to the floating-point format specification, or perform a floating-point assignment elsewhere in the program. This causes floating-point support to be loaded.

  5. In a mixed-language program, a C library was specified before a FORTRAN library when the program was linked. Relink and specify the C library last.

看完爲啥冒個runtime error出來也就釋然了
將那句改爲
printf("%f", (float) 4/2);

這樣運行就不會有問題了
不過
如果你前面有過“正常”使用%f加載了浮點,運行時是不會有這樣的錯誤的
只不過得不到正確的結果而已(整數除嘛)

看來要經常“溫習”啊,不然什麼基本的都忘光光了
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章