469,314 Members | 2,252 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,314 developers. It's quick & easy.

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

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
Jul 22 '05 #1
1 1338
"Harald Deischinger" <ha****************@med.ge.com> wrote...
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
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Chris Mantoulidis | last post: by
205 posts views Thread by Jeremy Siek | last post: by
6 posts views Thread by Jef Driesen | last post: by
145 posts views Thread by Sidney Cadot | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.