Does the C++ compiler generate "this" pointer for all member methods, or only for those who reference members? -
does c++ compiler generate hidden "this" pointer member methods, or reference members?
short answer: yes.
longer answer: well, if it's not using member variables, why member function in first place [and not static member function]. (yes, there may cases interface provides member method isn't doing member content, since it's doing printing error message calling function on wrong type, or it's "we need function", , in cases when nothing needs done, it's empty function).
since can use member function without compiler knowing (for example in case of different source files "use" , "definition" of function), compiler must follow same calling convention calls, whether this
pointer needed or not. it's of course possible if code if visible compiler inlines function or otherwise can make optimizations produce better code under circumstances allow this. "default" if compiler doesn't know better pass this
along function, whether needed or not.
Comments
Post a Comment