Bug in Singleton class

This is a discussion on Bug in Singleton class within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by anon It is possible to attach code files? Are you sure you don't have undefined behaviour elsewhere ...

  1. #16
    Registered User
    Join Date
    Dec 2007
    Posts
    7
    Quote Originally Posted by anon View Post
    It is possible to attach code files?

    Are you sure you don't have undefined behaviour elsewhere in the code?
    Sorry, but I can't post the code files. We must assume that I'm right :-)

    Code:
    pragma optimize ("t", off)
    before said function removed the bug as well.

  2. #17
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,447
    Basically, it's an optimization bug, then?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Registered User
    Join Date
    Dec 2007
    Posts
    7
    Quote Originally Posted by Elysia View Post
    Basically, it's an optimization bug, then?
    Ok, there is one class declared this way:

    Code:
    class __declspec(dllimport) ...
    The c'tor of this class calls the Singleton classes the first time. Now there are other classes calling the member function of the Singletons and without optimization it works but with optimization it doesn't. I narrowed one function down to:

    Code:
    for (int i=0; i<10; ++i)
    {
    }
    for (int i=0; i<10; ++i)
    {
    }
    double d = Params::Instance().getVal1();
    where a new Instance is only created if there are two or more of those dummy loops (optimization turned on). I don't now if the dll import has something to do with it or not. Imho it doesn't explain the random behaviour described above.

    Inlining still works perfectly with or without optimization.

    Thanks for your help!

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiler complaining about my singleton class
    By DavidP in forum C++ Programming
    Replies: 12
    Last Post: 06-09-2009, 02:30 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 01:09 PM
  4. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 04:01 PM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 01:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21