Tuesday, 15 May 2012

Force g++ to generate code for unused functions -



Force g++ to generate code for unused functions -

by default, g++ seems omit code unused in-class defined methods. illustration from previous question:

struct foo { void bar() {} void baz() {} }; int main() { foo foo; foo.bar(); }

when compiling g++ -g -o0 - c main.cpp, resulting object file contains references bar , not baz. adding --no-deafault-inline computer flags not help either. ideas how can forcefulness g++ generate code baz well?

rationale

the test coverage tool gcov reports unused methods non-executable if omitted final executable. however, meaningful reports want them reported executable-but-not-executed. this, need find way accomplish without having alter original source code.

a portable way add together "reference" (in ordinary sense, not c++ one, of word) these routines.

this simple

typedef void (foo::*funptr_t) (void); extern "c" const funptr_t tabfun[] = { &foo::bar, &foo::baz };

(i'm declaring array tabfun extern "c" sure array emitted, if not used)

you might seek -fno-inline argument gcc. customize gcc (e.g. melt) have such array added automatically (without touching source code), requires work.

g++ code-generation inline

No comments:

Post a Comment