I have a helper class in my program which has many static functions used in different classes of my program. E.g.
helper.h
:
Class helper {
public:
static void fn1 ()
{ /* defined in header itself */ }
/* fn2 defined in src file helper.cpp */
static void fn2();
}
Helper has only static member functions. So, no objects of helper are created by other modules. Helper functions are used in other modules like:
A.cpp
#include "helper.h"
A::foo() {
helper::fn1();
helper::fn2();
}
B.cpp
#include "helper.h"
B::foo() {
helper::fn1();
helper::fn2();
}
Does the compiler create separate copies of helper functions in A.cpp
and B.cpp
? I read some earlier posts and I gathered from the replies that compiler will create so. But when I print the address of fn1
and fn2
as printf("Address of fn1 is %p\n", &helper::fn1);
and printf("Address of fn1 is %p\n", &helper::fn1);
from both A.cpp
and B.cpp
, I get the same address. I'm confused now. Can someone clarify, If I'm missing something.
The reason I'm worried about multiple copies of helper functions (if it happens) is we are trying to reduce our executable size and wanted to optimize it.