Jump to content
  • Advertisement
Sign in to follow this  
orcfan32

What is a Macro?

This topic is 4836 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Quote:
Original post by orcfan32
What is a Macro?

Wiki on Macros
Quote:
Something you have to know to program games?
Not really, they're useful but should be avoided because they indiscrimatly replace text.

Share this post


Link to post
Share on other sites
they aren't needed and almost always should be avoided, they are commonly the sign of poor programming. Basically they tell the compiler to do some copy and pasting for you, however there are some quirks that you need to know in order for them to work correctly. I'm not saying that you should never use macros. I am saying that you could spend your time learning or doing something more useful.

Share this post


Link to post
Share on other sites
Quote:
Original post by Glak
they aren't needed and almost always should be avoided, they are commonly the sign of poor programming. Basically they tell the compiler to do some copy and pasting for you, however there are some quirks that you need to know in order for them to work correctly. I'm not saying that you should never use macros. I am saying that you could spend your time learning or doing something more useful.



in disagree macros are very useful they vcan take arguements and process different things they can also make dynamic changes very useful!

Share this post


Link to post
Share on other sites
"they can take arguments and process different things"

Except that they don't actually do any processing. Functions do though, so why not use a function? With a function you don't have to worry about scope, all of those extra parenthesis to safeguard precedence and all that other junk. Why would the average programmer and especially a beginner ever want to use a macro to do a function's job?

Share this post


Link to post
Share on other sites

#define func( n) LRESULT CALLBACK n(HWND, UINT, LPARAM, WPARAM)

func("WndProc");
int WINAPI etc....
....
// assuming WNDCLASSEX wcx
wcx.WndProc = WndProc;




i didnt do that accuratly im in a rush but it does do pre-processing
and functions cant dinamically modify things like that

Share this post


Link to post
Share on other sites
Quote:
Original post by C plus noob
in disagree macros are very useful they vcan take arguements and process different things they can also make dynamic changes very useful!
Macros can be useful, but inline and const do the same thing.

The macro

#define PI 3.14159
can be replaced by
const float PI = 3.14159

and

#define RADIUS_TO_CIRCUMFERENCE(r) (2*r*3.14159)
to
inline float RadiusToCircumference(float r) { return 2*r*3.14159; }

All of these do about the same thing in compile time, but the macros indiscriminately replace text while const & inline have additional error checking to prevent mistakes.

Plus, error message for misusing a const or inline are more user readable than error messages for misusing of a Macro.

Share this post


Link to post
Share on other sites
Quote:
Original post by C plus noob
note: macro's can reduce your .exe size more than functions

Er, since when? if anything, they would tend to increase it, because they force inlining. Do you have any support for your claim?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!