c++ - Size of pointer to member function varies like crazy -



c++ - Size of pointer to member function varies like crazy -

got subtle problem. got class compiled ms vs 2013 c++ compiler, 32 bit platform has size of 4 bytes. function pointer has sizeof 4 bytes. when class compiled same compiler included different project produce library, targeted fo 32 bit platform, class has *m_function pointer occupy 16 bytes! of course, when i'm instantiating class main project thinks class occupies 4 bytes , allocates memory size, while in reality occupies 16 bytes , causes memory overruns.

class cc1 { public: cc1(); void (cc1:: *m_function) (); };

i know size of pointer-to-member function can vary. qustion - compiler setting controls this? don't care 4 or 16 bytes - need them same. struct fellow member alignment settings same both projects. /vmm /vmg options? no mention of them in compiler settings in both projects.

by way, tried building x64 target , in case sizeof *m_function 8 bytes, main , libray project.

thank you.

see here docs page /vm options

if utilize '/vmg' compiler alternative pointer-to-member function 16 bytes you're telling compiler may not know size beforehand , has assume worst (virtual inheritance!).

if utilize '/vmb' compiler must know inheritance pattern struct before utilize , can utilize efficient method - in case of simple inheritance 4 bytes.

its in projects you've got '/vmg' set (which makes class 16 bytes) , in others dont (which makes class 4 bytes).

/vmb implicit default - check compiler command line libraries class 16 bytes /vmg

c++ pointers visual-c++ sizeof

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -