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

Discussion in 'C++' started by Harald Deischinger, Dec 15, 2003.

  1. 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
    Harald Deischinger, Dec 15, 2003
    #1
    1. Advertising

  2. "Harald Deischinger" <> 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
    Victor Bazarov, Dec 15, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cppaddict

    Complex Static Initializations

    cppaddict, Jul 28, 2004, in forum: C++
    Replies:
    1
    Views:
    323
    Dave Townsend
    Jul 28, 2004
  2. Andreas Wachowski
    Replies:
    6
    Views:
    662
    Rolf Magnus
    Aug 19, 2004
  3. vp
    Replies:
    9
    Views:
    288
  4. maadhuu
    Replies:
    2
    Views:
    234
    Maxim Yegorushkin
    Jul 23, 2005
  5. Victor \Zverok\ Shepelev

    Rubyish inst.var initializations

    Victor \Zverok\ Shepelev, Nov 23, 2006, in forum: Ruby
    Replies:
    11
    Views:
    187
    Victor \Zverok\ Shepelev
    Nov 25, 2006
Loading...

Share This Page