method-address longer then long long long

Hello there, I tried to print out addresses of class methods. But i have noted that they are greater then 'long long int'. So here is the question, how could i grasp them if they are 128 bit? Exists a data type greater then 'ull' ?

Here some example of failed casts to long long:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>

typedef unsigned long long int ull;

class X {
public:
    void f() {}
    
    void g() {}
    void g(int val) {}

};
int main()
{
    // returns 16, i.e. 128 bit
    std::cout << sizeof(&X::f) << " sizeof(&X::f)" << std::endl;
    // but 'ull' is 64 bit long
    std::cout << sizeof(ull) <<"  sizeof(unsigned long long)" << std::endl;
    
/*
    // all of these don't work:
    void * m_ptr = static_cast<void*>( &X::f );
    
    std::cout << reinterpret_cast<ull>( m_ptr )
    << std::endl;
    
    std::cout 
    << reinterpret_cast<ull>( &X::f ) 
    << std::endl;
    
    std::cout 
    << reinterpret_cast<ull>( 
    		static_cast< void(X::*)() >( &X::g ) 
    	) 
    << std::endl;
    
    std::cout 
    << reinterpret_cast<ull>( 
    		static_cast< void(X::*)(int) >( &X::g ) 
    	)
    << std::endl;
*/
    
    // all this works:
    int * i_arr = new int[16];
    // returns 8, i.e. 64 bit
    std::cout << sizeof(i_arr) << std::endl;
    std::cout << reinterpret_cast<ull>( i_arr ) << std::endl;
    delete[] i_arr;
}

edit: at title I mean of course 'long long', not 'long long long'
Last edited on
> how could i grasp them
use a pointer to member function.
The problem is that pointer-to-member functions on some implementations contain a lot of extra baggage.

According to Don Clugston, Visual C++'s member function pointers actually vary in size (!) depending on the nature of the class that they belong to and compiler settings.

You can't really do meaningful pointer arithmetic with them (at least not sanely), so why do you need them as an integer? You can declare a member-function pointer by writing return_type (class_name::*var_name)(function_parameters) = your_function;

But perhaps it's better to use a typedef return_type (class_name::*type_alias)(function_parameters);

Further, C++ offers no guarantees about the size of its data types, except in relative terms and that char is one machine byte.
In my opinion, you probably shouldn't really use raw member function pointers anyway. I think that when you need to bring stateful objects into the mix you should consider using <functional>.
Topic archived. No new replies allowed.