Click here to Skip to main content
15,888,527 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Exceptional coding Pin
Rick York6-Jun-09 8:38
mveRick York6-Jun-09 8:38 
GeneralRe: Exceptional coding Pin
Brady Kelly16-Jun-09 22:33
Brady Kelly16-Jun-09 22:33 
GeneralRe: Exceptional coding Pin
Judah Gabriel Himango17-Jun-09 5:15
sponsorJudah Gabriel Himango17-Jun-09 5:15 
GeneralRe: Exceptional coding Pin
Judah Gabriel Himango17-Jun-09 5:15
sponsorJudah Gabriel Himango17-Jun-09 5:15 
GeneralRe: Exceptional coding Pin
ssiegel22-Jun-09 14:42
ssiegel22-Jun-09 14:42 
GeneralMore an Implimentation Horror Pin
Nagy Vilmos2-Jun-09 11:04
professionalNagy Vilmos2-Jun-09 11:04 
GeneralRe: More an Implimentation Horror Pin
Moreno Airoldi2-Jun-09 23:42
Moreno Airoldi2-Jun-09 23:42 
GeneralI have no name, I don't exist PinPopular
Chris Losinger30-May-09 4:26
professionalChris Losinger30-May-09 4:26 
I have a little timer class that i use in optimizing code. It's a simple thing:

class CISTimer
{
public:
    CISTimer() {m_p = NULL; m_t = GetTickCount();}
    CISTimer(const char *p) {m_p = p; m_t = GetTickCount();}

    ~CISTimer()
    {
         DWORD d = GetTickCount() - m_t;
         char buf[30];
         _snprintf(buf, 29, "%4.2f  (%d)\n", (double)(d) / 1000.0, d);
         if (m_p)   {OutputDebugString(m_p);}
         OutputDebugString(buf);
    }

protected:
    const char *m_p;
    DWORD m_t;
};

grabs the time when it's created and outputs the elapsed time when it's destructed.

so, i'm working on a new project and want to see how long certain chunks of code are taking. i put the function calls inside curly braces, and drop some counters in:

{
   CISTimer("Func1");
   Func1(...);
}
...
{
   CISTimer("Func2");
   Func2(...);
}


so the counters will print their elapsed time when they go out of scope, thus telling me how long the function took, so i'll know where to start optimization.

but they're all coming up with an elapsed time of 0. that can't be true.

so i switch from GetTickCount to QueryPerformanceCounter. but, all those come up with 15 ticks - far too fast. the calls should be in the .25 second range.

so, i step through the code. the breakpoint gets to the counter instantiation, i step over it, and the timer immediately destructs - before going out of scope. did i break C++'s deterministic destruction?

after much head-scratching, i realized that i forgot to give names to those CISTimer objects. they were anonymous, and so they disappeared as soon as they were created. duh.

this is an unpleasant feature of C++.


GeneralRe: I have no name, I don't exist Pin
zlezj31-May-09 11:34
zlezj31-May-09 11:34 
GeneralRe: I have no name, I don't exist Pin
Chris Losinger31-May-09 11:51
professionalChris Losinger31-May-09 11:51 
GeneralRe: I have no name, I don't exist Pin
Thomas Weller31-May-09 20:14
Thomas Weller31-May-09 20:14 
GeneralRe: I have no name, I don't exist [modified] Pin
Chris Losinger1-Jun-09 0:58
professionalChris Losinger1-Jun-09 0:58 
GeneralRe: I have no name, I don't exist Pin
zlezj31-May-09 21:23
zlezj31-May-09 21:23 
GeneralRe: I have no name, I don't exist Pin
johannesnestler3-Jun-09 23:27
johannesnestler3-Jun-09 23:27 
GeneralRe: I have no name, I don't exist Pin
Chris Losinger4-Jun-09 0:57
professionalChris Losinger4-Jun-09 0:57 
GeneralRe: I have no name, I don't exist Pin
supercat94-Jun-09 5:36
supercat94-Jun-09 5:36 
GeneralRe: I have no name, I don't exist Pin
Chris Losinger4-Jun-09 5:51
professionalChris Losinger4-Jun-09 5:51 
GeneralRe: I have no name, I don't exist Pin
supercat94-Jun-09 8:33
supercat94-Jun-09 8:33 
GeneralRe: I have no name, I don't exist Pin
Chris Losinger4-Jun-09 8:43
professionalChris Losinger4-Jun-09 8:43 
GeneralRe: I have no name, I don't exist Pin
Jörgen Sigvardsson12-Jun-09 6:47
Jörgen Sigvardsson12-Jun-09 6:47 
GeneralQuantity FTW! Pin
Brady Kelly28-May-09 22:15
Brady Kelly28-May-09 22:15 
GeneralRe: Quantity FTW! Pin
Tristan Rhodes28-May-09 23:32
Tristan Rhodes28-May-09 23:32 
GeneralRe: Quantity FTW! Pin
Ian Shlasko29-May-09 10:16
Ian Shlasko29-May-09 10:16 
GeneralRe: Quantity FTW! Pin
Jörgen Sigvardsson12-Jun-09 6:50
Jörgen Sigvardsson12-Jun-09 6:50 
GeneralRe: Quantity FTW! Pin
Brady Kelly12-Jun-09 6:53
Brady Kelly12-Jun-09 6:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.