- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- sizeof (<pointers to member function>)
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2011 09:45 PM
01-31-2011 09:45 PM
Hi,
Pointers to member functions (methods) have
* 64 bits in 32-bit modeel
* 128 bits in 64-bit model.
1. What is the reason for that?
2. Pointer to member function has more bits than regular pointer.
What does 'pointer to member function' contain?
Thanks,
Alex
----------------------------------
HP-UX B.11.23 U ia64
aCC: HP C/aC++ B3910B A.06.25.01 [May 16 2010]
// ====== a3264.cpp: BEGIN ======
#include
#include
#define SHOW(x) std::cout << #x << ", \tsizeof = " << sizeof(x) << ", typeid = " << typeid(x).name() << std::endl
struct Dummy
{
};
typedef void (*func_t)();
typedef char Dummy::*ptr_member_t;
typedef void (Dummy::*method_t)();
int main()
{
SHOW(ptr_member_t);
SHOW(func_t);
SHOW(method_t);
return 0;
}
// ====== a3264.cpp: END ======
Compilation
> aCC +DD32 -AA a3264.cpp -o a32.out
> aCC +DD64 -AA a3264.cpp -o a64.out
Running
> a32.out
ptr_member_t, sizeof = 4, typeid = M5Dummyc
func_t, sizeof = 4, typeid = PFvvE
method_t, sizeof = 8, typeid = M5DummyFvvE
> a64.out
ptr_member_t, sizeof = 8, typeid = M5Dummyc
func_t, sizeof = 8, typeid = PFvvE
method_t, sizeof = 16, typeid = M5DummyFvvE
Solved! Go to Solution.
- Tags:
- sizeof
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2011 01:26 AM
02-01-2011 01:26 AM
Solution1) Pointers to data have a 32/64 bit pointer
2) Pointers to functions have a 32/64 bit pointer to a function descriptor.
3) Pointers to member data are offsets (NULL == -1)
4) Pointers to member functions have two fields. The first is used as either a pointer to function descriptor or virtual table offset (biased by 1 byte) for virtual calls.
The second is the "this" pointer adjustment.
>2. Pointer to member function has more bits than regular pointer.
It has to have the "this" pointer adjustment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2011 02:02 AM
02-01-2011 02:02 AM
Re: sizeof (<pointers to member function>)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2011 01:20 AM
02-03-2011 01:20 AM
Re: sizeof (<pointers to member function>)
> 3) Pointers to member data are offsets (NULL == -1)
HP-UX B.11.23 U ia64
aCC: HP C/aC++ B3910B A.06.25.01 [May 16 2010]
=========== a.cpp ===========
#include
struct Dummy
{
int m_int1;
char m_ch1;
double m_double1;
int m_int2;
};
int main()
{
std::cout << &Dummy::m_int1 << std::endl;
std::cout << &Dummy::m_ch1 << std::endl;
std::cout << &Dummy::m_double1 << std::endl;
std::cout << &Dummy::m_int2 << std::endl;
return 0;
}
===============================
Compilation
> aCC +DD64 -AA a.cpp
Running
> ./a.out
1
1
1
1
===================
How can we get actual offsets?
Thanks
Alex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2011 04:07 AM
02-03-2011 04:07 AM
Re: sizeof (<pointers to member function>)
Pointers to members are thingees. You can't really use them with iostream without a hammer.
What the compiler did was a boolean conversion and checked for non-NULL.
#include
struct Dummy {
int m_int1;
char m_ch1;
double m_double1;
int m_int2;
};
int main() {
int Dummy::* tm_int1 = &Dummy::m_int1;
char Dummy::* tm_ch1 = &Dummy::m_ch1;
double Dummy::* tm_double1 = &Dummy::m_double1;
int Dummy::* tm_int2 = &Dummy::m_int2;
printf("&Dummy::m_int1: %p\n", reinterpret_cast
printf("&Dummy::m_ch1: %p\n", reinterpret_cast
printf("&Dummy::m_double1: %p\n", reinterpret_cast
printf("&Dummy::m_int2: %p\n", reinterpret_cast
}
For +DD64:
&Dummy::m_int1: 0000000000000000
&Dummy::m_ch1: 0000000000000004
&Dummy::m_double1: 0000000000000008
&Dummy::m_int2: 0000000000000010
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2011 04:45 AM
02-03-2011 04:45 AM