S
sh.vipin
Below is the outcome of a source code and code itself in the same
order. We know that every function name behaves like a pointer to
function also. But at the same time, based on result, function name
also has the same value as its address(1st and 3rd line in result are
same).
i.e. it seems that for any function
int fun(){
.....
}
following holds true always.
&fun == fun
Otherwise, i think there is no way
that (**************fun)() , fun() and (*fun)() could behave in same
way.
My queries are
1. Is it an ANSI C Standard or just a compilers' implementation
methodology.
2. I believe that *fun should give the address of a location from
where the code for function starts. It should be in code segment. Then
how come a variable "fun" (i.e. function name itself ) is also having
an address which lies in code segment.
------------RESULT-------------
Address OF 4198728
Address OF 4202500
Address IN 4198728
Address IN 4198728
I watched "A Wednesday" this friday.
I watched "A Wednesday" this friday.
-------------------------
/* CODE */
int gef(){
printf("\n I watched \"A Wednesday\" this firday.");
}
int (*z)() =gef;
int main (int argc, char *argv[]){
printf("\n Address OF %u ",&gef);
printf("\n Address OF %u ",&z);
printf("\n Address IN %u ",gef);
printf("\n Address IN %u ",z);
(****z)();
(*****gef)();
return 0;
}
-vipin
order. We know that every function name behaves like a pointer to
function also. But at the same time, based on result, function name
also has the same value as its address(1st and 3rd line in result are
same).
i.e. it seems that for any function
int fun(){
.....
}
following holds true always.
&fun == fun
Otherwise, i think there is no way
that (**************fun)() , fun() and (*fun)() could behave in same
way.
My queries are
1. Is it an ANSI C Standard or just a compilers' implementation
methodology.
2. I believe that *fun should give the address of a location from
where the code for function starts. It should be in code segment. Then
how come a variable "fun" (i.e. function name itself ) is also having
an address which lies in code segment.
------------RESULT-------------
Address OF 4198728
Address OF 4202500
Address IN 4198728
Address IN 4198728
I watched "A Wednesday" this friday.
I watched "A Wednesday" this friday.
-------------------------
/* CODE */
int gef(){
printf("\n I watched \"A Wednesday\" this firday.");
}
int (*z)() =gef;
int main (int argc, char *argv[]){
printf("\n Address OF %u ",&gef);
printf("\n Address OF %u ",&z);
printf("\n Address IN %u ",gef);
printf("\n Address IN %u ",z);
(****z)();
(*****gef)();
return 0;
}
-vipin