Unexpected struct behavior in Borlands Turbo C++ 3

This tip submitted by Raza Sayed on 2006-09-26 09:40:01. It has been viewed 13565 times.
Rating of 5.2 with 117 votes



Hi,

I have noticed that the following code does not work in Borlands Turbo C++ 3.0 IDE , even though the code appears to be perfectly alright. Now this can be really frustrating for a person new to C programming and hence I decided to document this case and its resolution over here.

The program abruptly terminates with \\"Floating point formats not linked\\" error message.
In fact nothing is wrong with the program however the error results because of the way Borlands Turbo C++ 3.0 IDE handles floating point numbers . This is one of the classic examples where theory breaks away from practice . Hence programmers are advised that in addition to learning the concepts of the language they should also focus on learning more about the environment or platform they develop their programs on . Something may sound good in theory but may not work out in practice because of the way the language has been implemented by the people who develop the development environments . I wont go into the detailed analysis of this error, but would simply show the way to resolve it. In case you would like to learn more about this you can visit : http://bdn.borland.com/article/15204.

Problem
-------
struct test
{
char name[30] ;

int num ;

float deci ;


} ;

void main()
{
struct test t ;

void fun(struct test *);

clrscr();

fun(&t);

printf("\n%s",t.name);

printf("\n%d",t.num);

printf("\n%6.2f",t.deci);

getch();



}

void fun(struct test * ptr)
{

printf("Enter name , age and basic salary : ");

scanf("%s %d %f",ptr->name,&ptr->num,&ptr->deci);


}

Program abruptly terminates with "Floating point formats not linked" error message.


Resolution
----------
Add the following two lines to the beginning of the program

extern _floatconvert ;
#pragma extref _floatconvert

So, the program now becomes :

extern _floatconvert ;
#pragma extref _floatconvert

struct test
{
char name[30] ;

int num ;

float deci ;


} ;

void main()
{
struct test t ;

void fun(struct test *);

clrscr();

fun(&t);

printf("%s\n",t.name);

printf("%d\n",t.num);

printf("%6.2f\n",t.deci);

getch();



}

void fun(struct test * ptr)
{

printf("Enter name , age and basic salary : ");

scanf("%s %d %f",ptr->name,&ptr->num,&ptr->deci);


}

Happy Programming !! :)





More tips

Help your fellow programmers! Add a tip!