A function give not error msg

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kalrasoft
    New Member
    • Feb 2009
    • 13

    A function give not error msg

    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.
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    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.

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      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

      • Kalrasoft
        New Member
        • Feb 2009
        • 13

        #4
        Originally posted by donbock
        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.
        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

        • donbock
          Recognized Expert Top Contributor
          • Mar 2008
          • 2427

          #5
          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

          • Kalrasoft
            New Member
            • Feb 2009
            • 13

            #6
            Thanx Donbock sir! 1st there is not run time error.2ndly i read in a book that when miss prototype the error is generate by linker not compiler.plz be away my confusion.

            Comment

            • donbock
              Recognized Expert Top Contributor
              • Mar 2008
              • 2427

              #7
              Originally posted by Kalrasoft
              i read in a book that when miss prototype the error is generate by linker not compiler.
              The linker has two major purposes. First, it resolves cross-references between object files (for example, when one file calls a function defined in another file). Second, it locates the various memory sections to specific addresses.

              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

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #8
                Originally posted by Kalrasoft
                i added a function to the standard library maths.lib
                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,

                Jos

                Comment

                • Kalrasoft
                  New Member
                  • Feb 2009
                  • 13

                  #9
                  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

                  • Kalrasoft
                    New Member
                    • Feb 2009
                    • 13

                    #10
                    [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

                    • Kalrasoft
                      New Member
                      • Feb 2009
                      • 13

                      #11
                      Originally posted by JosAH
                      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,

                      Jos
                      Thanx for advising Sir.

                      Comment

                      Working...