Hello to all my friend!i added a function to the standard library maths.lib in turbo c++ compiler.bt i didnt declare prototype for that function and not use a header file for that.bt there is no error.How it comes possible?plz explain me.
A function give not error msg
Collapse
X
-
First guess is that if it returns int (or void ) and accept some float/double/int/pointers arguments, compiler passes them correctly based on their types, and if arguments in point of call are constants ( e.g. f(2) ), actual function parameters are int or double, so as compiler passes everyting ordinal expanded to int and float constants as double, everything is ok. -
When you say "there is no error", do you mean (there is no compile-time error) or (there are neither compile-time nor perceptible run-time errors)?
Are you calling this new function? If not, then a missing prototype wouldn't provoke any errors.Comment
-
yeah! obviouly sir i called this function.and it was the function to calculate fact. of a number.and i dont include its header "fact.h" and it didnt give linker error.why there is no error.thanx n regards.Comment
-
1. If you call an undeclared function then the C Standard mandates that the function return value is assumed to be int and the arguments are handled as in the pre-ANSI, pre-prototype, days of K&R C where the argument type is inferred from the value/variable that is passed in the function call. This is not a formal error condition so it is not surprising that you don't get a compiler error. It is disappointing that you don't get a compiler warning.
2. What is the prototype of your function? If it doesn't match the inferred K&R prototype then you can expect bugs. However, there need not be a dramatically announced run-time error -- you will just get the wrong answer.
3. You mentioned "linker error". A missing or erroneous header file can certainly cause a compiler error, but you have to put something unusual in the header to provoke a linker error.Comment
-
I don't see why a missing function prototype would interfere with either of those activities.
Can you recall the explanation in your book for why a missing prototype manifests as a linker error? It is difficult to respond to a bald statement.Comment
-
You shouldn't do that; in your other post you wanted to mutilate the Standard library and now you're mutilating the math library; don't do that. Create your own library and also create the appropriate .h files for it.
kind regards,
JosComment
-
Sorry for late.bt i was busy.yes i remember that book lines.these r "it is also possible to have errors during linking process.for instance,linker will issue an error message if u have not included the file stdio.h.The programm will compile correctly,bt will fail to link system library."So sir plz read these lines carefully n solve my confusion.Thanx and regards.Comment
-
[QUOTE=newb16;34 59464]First guess is that if it returns int (or void ) and accept some float/double/int/pointers arguments, compiler passes them correctly based on their types, and if arguments in point of call are constants ( e.g. f(2) ), actual function parameters are int or double, so as compiler passes everyting ordinal expanded to int and float constants as double, everything is ok.
Thanx for ans.and i am using a function that give/take int type.so i think it was the reason there is not any error.Comment
-
Comment
Comment