Jump to content

  • Log In with Google      Sign In   
  • Create Account

Washu

Member Since 24 Mar 2001
Online Last Active Today, 11:58 AM

Posts I've Made

In Topic: SFML Unhandled Exception error (Visual Studio 2013)

Yesterday, 11:30 PM

You're accessing a null pointer. Don't do that.

Don't know where, in your code, but maybe you didn't initialize something you were supposed to.

In Topic: Impossible to Detect Window Starting Unfocused? (Windows)

Yesterday, 07:57 PM

Why would you expect to receive messages about losing the focus of the window you created... when you never had it in the first place?

Additionally: attempting to steal the focus back from the user is a bad idea. The user decides where the focus goes, you should write your code to handle this situation properly (i.e. "don't do something stupid like crash or take back the focus.")

If you really want to notify the the user that the application is ready for use: use the windows taskbar notification API's to highlight your application icon (see this).

In Topic: Constructor gotcha's?

Yesterday, 05:51 PM

are there any "gotcha!"s to look out for?

 
One detail I've bumped recently, is that object allocation is "indeterminately sequenced with respect to the evaluation of the constructor arguments in a new-expression".
I've tried clang++ instead of g++, and perfectly working code crashed.
Problem was exactly about that rule.
I was passing arguments to constructor, derived from memory pool's state (Lua VM stack, actually).
Object has its own allocator, changing that state upon object's creation. So exact ordering was critical, but I didn't noticed that because gcc evaluated arguments first, while clang decided to allocate object first, and only after that evaluate constructor arguments.
#include <stdio.h>
#include <stdlib.h>

int arg_func()
{
    printf("Args calculated\n");
    return rand();
}

struct A
{
    A(int val)
    {
        printf("A::A(int)\n");
    }

    static void* operator new(size_t size)
    {
        printf("A::operator new\n");
        return malloc(size);
    }

    static void operator delete(void* ptr)
    {
        free(ptr);
    }
};

int main()
{
    delete new A(arg_func());
    return 0;
}
If you compile it with g++ you will get output:
Args calculated
A::operator new
A::A(int)
But with clang++ you'll get:
A::operator new
Args calculated
A::A(int)
Probably you will never notice that if you stick with MSVS only. But it's still "gotcha" case.


The order of evaluation of function arguments has always been unspecified. This isn't a gotcha so much as just depending on unspecified behavior.

In Topic: OO where do entity type definitions go?

23 January 2015 - 09:33 PM

As for where you put the data when you want it in memory... where ever you want.

 
so there is no best method then?

In software development, "best" is relative.

In Topic: OO where do entity type definitions go?

23 January 2015 - 08:47 PM

If you're data-driving things, then the variables should be coming from your data.

As for where you put the data when you want it in memory... where ever you want.

PARTNERS