Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   function (http://www.go4expert.com/forums/function-t29345/)

Rajesh M. Kanojia 13Dec2012 01:12

dear members
can any one tell me where exactly function get loaded at run time in c program.
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

xpi0t0s 16Dec2012 04:10

Re: function
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.

iranjit 5Jan2013 18:39

Re: function
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.

xpi0t0s 7Jan2013 14:13

Re: function
"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.

JonSon 17May2013 18:24

Re: function
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 .

All times are GMT +5.5. The time now is 19:07.