Copyrights @ Journal 2014 - Designed By Templateism - SEO Plugin by MyBloggerLab

Monday, July 11, 2005

scanf : 'floating point formats not linked'

Have you seen this error in your C or C++ programs, the programs are very simple,
float myFloat; scanf("%f",&myFloat); /* This step results in abnormal termination or program with an error as scanf : floating point formats not linked. */
This can be seen at runtime, when the line is called during execution, there is a great chance based on platform and compiler, you will see this error. I discovered this during development of linked list program which would have some float manipulation. After a considerable research I realised that, it can happen when I am using the Borland C++ or Turbo C as compiler.
"Floating point formats not linked" is a Borland run-time error (Borland C or C++, Turbo C or C++). Borland's compilers try to be smart and not link in the floating- point (f-p) library unless you need it. Alas, they all get the decision wrong. One common case is where you don't call any f-p functions, but you have %f or other f-p formats in scanf() or printf() calls. The cure is to call an f-p function, or at least force one to be present in the link.
- via
"" also talks about solution, and it works as follws.
To do that, define this function somewhere in a source file but don't call it: static void forcefloat(float *p) { float f = *p; forcefloat(&f); }
It doesn't have to be in the module with the main program, as long as it's in a module that will be included in the link. If you have Borland C++ 3.0, the README file documents a slightly less ugly work-around. Insert these statements in your program: extern unsigned _floatconvert; #pragma extref _floatconvert
This also means that you might not see this on some platforms like linux, and AIX versions. I could not replicate that on any other platform than Windows.