Strings and Definitions

Started by
13 comments, last by SiCrane 15 years, 8 months ago
Quote:Original post by WinRad
Well that seems to make sense... Hmm but what if the macros I use are very long and specific and I only need them in one case? For example in my game I use a macro called Player1UpDef which is very specific and most likely would never be used by me again because I add def to the end of every #define macro.

Yes, then you're unlikely to get any name conflicts, so you're probably safe from that particular problem... But what did it buy you?
Why not just use the non-macro alternatives and be safe?

The point is that (almost) anything you do with macros, can be done as easily, and much much safer without them.

Quote:
Also I need to know the VK for the @ sign :).

As far as I know, all visible characters just use their ASCII code as VK.
A's virtual keycode is the integer value of 'A', and @'s is '@'.
Advertisement
OK cool thank you :).

As with your "be safe" question. The reason I don't simply use variables is because the macros can be defined right at the top without any problems and I just find it easier to customize my app with macros then variables... because the variables end up cluterring so... well that's my reason.

Thanks again :).
Quote:Original post by WinRad
OK cool thank you :).

As with your "be safe" question. The reason I don't simply use variables is because the macros can be defined right at the top without any problems and I just find it easier to customize my app with macros then variables... because the variables end up cluterring so... well that's my reason.

Thanks again :).

A good design, most likely one that uses classes, would avoid the clutter that you speak of. Basically, if it works for you, fine, but don't think that clutter is a problem only solvable by an ugly work-around. Just something to remember.
Quote:Original post by WinRad
As with your "be safe" question. The reason I don't simply use variables is because the macros can be defined right at the top without any problems and I just find it easier to customize my app with macros then variables... because the variables end up cluterring so... well that's my reason.


That's not a very good reason. Tell me why one of these is more cluttered than the other.

#define PI 3.14const double pi = 3.14;


What "problems" do you have with defining variables at the top? How much harder is it to change the value of a global constant than it is to change a #define? The benefits far outweigh the downsides of using real variables.
Quote:Original post by Spoonbender
As far as I know, all visible characters just use their ASCII code as VK.
A's virtual keycode is the integer value of 'A', and @'s is '@'.

Virtual key codes are key codes. Assuming a standard US English keyboard, shift-2 would generate an '@'; however, the virtual key code generated would still be VK_2. If you wanted to check the characters generated by a key press you could try using WM_CHAR or WM_UNICHAR.

This topic is closed to new replies.

Advertisement