"Optimization" with source file contaiing only static functions and initializations

H

Harald Deischinger

I am using a source file with the following style (I know it is not
very beautiful but it is working):

SRC1.cpp:

static void vFoo() {
// bla bla bla
}
static int iInit1(name, fun) {
// access some global variables to register fun as name.
}
static int _tmp1 = iInit1("void", vFoo);


Please not that this example is very simplified. In the real example
for some data types functions are listed in a global data strucuture
so that they can be found by name.

This is working fine a long is in SRC1.cpp there is a least one other
function that is called from a different source file. But if that is
missing it seems that the whole source file is removed from the
resulting application. The initialization functions are not called.
And it is not possible to set a breakpoint in any of the functions.


Any ideas what might cause this "optimization"?
The linker option /opt:noref does not help.

harald
 
V

Victor Bazarov

Harald Deischinger said:
I am using a source file with the following style (I know it is not
very beautiful but it is working):

SRC1.cpp:

static void vFoo() {
// bla bla bla
}
static int iInit1(name, fun) {
// access some global variables to register fun as name.
}
static int _tmp1 = iInit1("void", vFoo);


Please not that this example is very simplified. In the real example
for some data types functions are listed in a global data strucuture
so that they can be found by name.

This is working fine a long is in SRC1.cpp there is a least one other
function that is called from a different source file. But if that is
missing it seems that the whole source file is removed from the
resulting application. The initialization functions are not called.
And it is not possible to set a breakpoint in any of the functions.


Any ideas what might cause this "optimization"?
The linker option /opt:noref does not help.

Linker options are OT here. They have nothing to do with the language.

Try declaring your temporary object "extern".

Victor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top