function

Discussion in 'C' started by Rajesh M. Kanojia, Dec 12, 2012.

  1. Rajesh M. Kanojia

    Rajesh M. Kanojia New Member

    Joined:
    Dec 9, 2012
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    INDIA
    dear members
    can any one tell me where exactly function get loaded at run time in c program.
    ex:-
    suppose i call 2 function in main().
    1- abc();
    2- xyz();
    my question is that is abc() and xyz() occupy memory if yes then where
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Why do you want to know?

    They are loaded with main in the TEXT part of the executable. You will need to learn assembly language programming to know what that really means. Hence the above question. If you want to know the addresses of the functions, that's simple, just define a function pointer to point to those functions, then pass the pointer into printf and use the format mask %08lx to display the address.
     
  3. iranjit

    iranjit New Member

    Joined:
    Jan 5, 2013
    Messages:
    4
    Likes Received:
    2
    Trophy Points:
    0
    Home Page:
    http://www.programiz.com
    I am sorry but, it is hard to understand your question.

    Overloaded functions have same name but, different arguments(either different number of arguments or different types of argument). Remember, if two functions have same name and argument/s but different return type then, don't assume these two functions are overloaded functions. Instead compiler gets confused and displays error.

    If there are two overloaded functions then, compiler doesn't know which function to call until run-time and executes the appropriate function in accordance with the argument passed.
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    "Why do you want to know" is not a difficult question to understand. But I can't answer your original question until I know, er, why you want to know.

    Your original question has nothing to do with overloaded functions because abc() and xyz() differ in name. But with overloaded functions they differ in parameters so the compiler can tell which function to call by looking at the parameters. So if you have abc() and abc(int), then the compiler can determine which to call by whether or not you pass an int, and if you try to default the int param (e.g. void abc(int x=0)) then the compiler will throw an error because it won't be able to determine if a call like abc(); means call abc() or abc(0).

    By the way, the term "run time" has nothing to do with the compiler. The compiler compiles the code to object code. The linker links the object code with the relevant libraries to make executable. When you run the program, that is "run-time" and the compiler is not involved.
     
    shabbir likes this.
  5. JonSon

    JonSon New Member

    Joined:
    May 17, 2013
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    online service provider
    Location:
    UK
    Home Page:
    https://www.facebook.com/Sarkari.Noukri.Chahiye.Kya
    An action performed by a device department or person that produces a result.The return value of the first non-failed function without executing successive functions .
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice