Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualblueshogun96

Posted 21 March 2013 - 10:18 PM

Wow, you guys are mean! tongue.png

 

 

I have a question. Why are these macros and not methods or even functions?

/* Useful macros */
#define safe_delete(x) if(x) { delete x; x = NULL; }
#define fail_safe(x) if(!x) return;

 

Does it matter?

 

 

Another question. Why are you using

/* Global class instance */
game_app_t* This = NULL;
 

 

and not

 

int main( int argc, char* argv[] )
{
    app = new game_app_t();
    /* where game_app_t is an actual class */
    return 0;
}
 

 

Well, you can't explicitly use "this" in a static function, hence why I created a copy of it.  I didn't feel like changing the code structure again if I didn't have to.  Second, I forgot to add the '()'.

 

Mr. Hodgeman, I'm a "heap freak". smile.png

 

Oh, and the macros were just a quick way of getting around. Second, macros can be more optimal (IMO) and for small operations I'd much rather use them to do things that require 2 lines of code than an actual short function.  Even if you inline a function that you use frequently, a macro is faster because the compiler doesn't have to push the parameters, call the function, pop them off the stack, do push the registers (eax, ebx, etc.), do whatever, restore the registers and return.  I know that it doesn't impact performance really, but after writing and reading so much assembly code, I tend to think about these things a bit too much.

 

Shogun


#1blueshogun96

Posted 21 March 2013 - 10:05 PM

Wow, you guys are mean! tongue.png

 

 

I have a question. Why are these macros and not methods or even functions?

/* Useful macros */
#define safe_delete(x) if(x) { delete x; x = NULL; }
#define fail_safe(x) if(!x) return;

 

Does it matter?

 

 

Another question. Why are you using

/* Global class instance */
game_app_t* This = NULL;
 

 

and not

 

int main( int argc, char* argv[] )
{
    app = new game_app_t();
    /* where game_app_t is an actual class */
    return 0;
}
 

 

Well, you can't explicitly use "this" in a static function, hence why I created a copy of it.  I didn't feel like changing the code structure again if I didn't have to.  Second, I forgot to add the '()'.


PARTNERS