Reputation: 15493
When compiling C++ with GCC 4.4 or MSVC is it possible to get the compiler to emit messages when a function is inlined?
Upvotes: 12
Views: 724
Reputation: 47418
With g++, I don't think you can make g++ report that, but you can examine the resulting binary with any tool that shows symbols, nm
for example:
#include <iostream>
struct T {
void print() const;
};
void T::print() const { std::cout << " test\n" ; }
int main()
{
T t;
t.print();
}
~ $ g++ -O3 -Wall -Wextra -pedantic -o test test.cc
~ $ nm test | grep print
0000000000400800 t _GLOBAL__I__ZNK1T5printEv
0000000000400830 T _ZNK1T5printEv
vs
#include <iostream>
struct T {
void print() const { std::cout << " test\n" ; }
};
int main()
{
T t;
t.print();
}
~ $ g++ -O3 -Wall -Wextra -pedantic -o test test.cc
~ $ nm test | grep print
(no output from nm in the second case)
EDIT: Also, profilers may be of use. gprof shows, on these two examples:
0.00 0.00 0.00 1 0.00 0.00 global constructors keyed to _ZNK1T5printEv
0.00 0.00 0.00 1 0.00 0.00 T::print() const
vs. just
0.00 0.00 0.00 1 0.00 0.00 global constructors keyed to main
Upvotes: 2