• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

simulator

#define gridSz 16 versus Const Int gridSz=16; ????

10 posts in this topic

Hi- Having recently discovered #defines, I'm wondering why anyone would use constant variables instead???? What do you use?? Am I missing something???? Is there any difference- speed wise etc? I would imagine #defines are better because they become part of the compiled program memory versus constant variables that have to be accessed separately?? Thanx Edited by - simulator on August 2, 2001 6:26:01 PM Edited by - simulator on August 2, 2001 6:30:07 PM
0

Share this post


Link to post
Share on other sites
defines get put in before your program compiles.

You can even things like this:

#define printg printf


Although I don''t know why you''d want to!
0

Share this post


Link to post
Share on other sites
Hi & thanx,

Yes I know about how defines work...
Perhaps constant variables would be those defined at run time eg:


Const long lPitch;

(ie: where lPitch must be determined only once the program is running) (not sure this is even permitted.... must try it)


thanx


--- yes it works- so that must be why???

But still, even for plain, known-ahead-of-time constants- what do most people use: #define?????

Edited by - simulator on August 2, 2001 6:42:59 PM

Edited by - simulator on August 2, 2001 6:49:10 PM
0

Share this post


Link to post
Share on other sites
Constant values are placed inline in the same way that #defines are, so there''s no speed difference. I use const for constants, and #define for other things, but both are quite acceptable. Do what looks nice to you.
0

Share this post


Link to post
Share on other sites
Here''s the difference:
Constants are just like normal variables, with the exception that they cannot be changed.

Defines are simply "substitutions" in code. Take an example:

#define NUMBER 23
...
array[NUMBER] = 113;

is literally exactly the same as

array[23] = 113;

However, defines are not type-checked. Therefore, a number of goofy problems may get right past the compiler and linker (not positive about that, but pretty damned sure). Take an example:

#define NUMBER "AKLSJFD"

array[NUMBER] = 113;

Obviously, "AKLSJFD" isn''t a valid array indice, but since it''s defined in a macro, it might get by the compiler. (Again, not dead sure about this).

To summarize: either one is fine, but just remember that #define-s are less safe than consts.

-Normie

"But time flows like a river... and history repeats."
...
So...what about beaver dams?
0

Share this post


Link to post
Share on other sites
Normie - you''re actually mistaken there - #defines are, as you said, substitutions. So:

#define NUMBER "AKLSJFD"
array[NUMBER] = 113;

would become:

array["AKLSJFD"] = 113;

...which raises a compiler error. However:

#define INCREMENT(a, b) a += b

If you pass a char* and an float to that function, you''ll get an error which doesn''t seem to make sense (Illegal use of floating point). And that''s the only problem I''ve ever seen coming from lack of type safety. It''s not actually as bad as some people make out.
0

Share this post


Link to post
Share on other sites
#define''s are also nasty in that if you do something like

#define IncCheck(a,b) (a++ < b++) ? a++ : b++

and then
IncCheck(i,j)
both i & j will be incremented at least once,
because the direct substitution expands to
(i++ < j++) ? i++ : j++

The const keyword was introduced to allow the compiler to type check arguments (can''t do that with macros) and the inline keyword was used to fix the expansion problem that macros suffer. The only time I''d recommend using macros is conditional code compilation, ie
#if defined _DEBUG
printf("This is a debug version");
#endif

Brad
0

Share this post


Link to post
Share on other sites
brad_beveridge: If you wrote that as an inline function, using the same code, you''d get the exact same logic error. I think what you meant was more like this:

#define Check(a, b) ((a > b) ? a : b)
Check(a++, b++);

Which would of course cause an error. But show me someone who would write something like that and not see the problem within a few minutes, and I''ll show you someone who needs to learn the basics of c.

There are still advantages that macros have over inline functions. In some cases, it''s just that it requires less code than the inline function, and in some cases, nothing can go wrong:

#define CREATEWINDOW(Title) CreateWindowEx(0, "randomclassname", Title, WS_VISIBLE, 0, 0, 640, 480, NULL, NULL, GetModuleHandle(NULL), NULL)

And although the following isn''t the best example, there are some things that macros can do that inline functions cannot:

// Declare and clear a DirectX structure:
#define DECLARE_STRUCT(type, var) type var; ZeroMemory(&var, sizeof(var)); var.dwSize = sizeof(var)


In summary, use macros where appropriate, and use inline functions where they''re appropriate. A macro should use each parameter exactly once (to avoid the Check(a++, b++) problem), and should be commented to describe the parameters if the parameters are not obvious.
0

Share this post


Link to post
Share on other sites
Opps - my bad, Beer Hunter - you wrote what I ment to write I agree that macros can be good, but they have to be used right - we use them heavily where I work to mask certain things (we use ANSI C) sometimes they''re great, at other times a nightmare. Also VC++ doesn''t cope all that well with them, especially when debugging.

Brad
0

Share this post


Link to post
Share on other sites