Hi LQ,
I have a question regarding function adress.
Maybe it is easier to understand my problem with a bit of code:
Code:
#include <iostream>
2 using namespace std;
3 void func(void)
4 {
5 cout << "Did you call me?" << endl;
6 return;
7 }
8 int main(int argc,char* argv[])
9 {
10 void (*f)() = &func;
11 int i = 0;
12
13 cout
14 << "without casting :" << endl
15 << "f: " << f << " main: " << main << endl
16 << "with casting :" << endl
17 << "f: " << (long)f << " main: " << (long)main
18 << endl;
19 cout << "With variables: " << endl << &i << " " << long(&i) << endl;
20 return 0;
21 }
and the output I get :
Code:
[Alpha][Tests] ./test_pointfunc
without casting :
f: 1 main: 1
with casting :
f: 4196516 main: 4196550
With variables:
0x7fff10662df4 140733468519924
Why do I get a simple '1' for the function adress when not casted to couble? (while I get an hex adress for a variable). Also, why is it the same result for all the function (I did it here with the main, but if I had another function, I get the same results).
Is it machine specific, is it that I did something wrong, or is it something I didn't understand?
Cheers,
Loic.