I'm using visual studio how can i create unique numbers for my #define statements ??
Posted on 2005-07-11 16:00:36 by AceEmbler
In which context do they have to be unique, and why do they have to be unique? Also, there might be better alternatives to #define ... but death can probably give a better explanation than I can ;)
Posted on 2005-07-11 16:08:22 by f0dder

In which context do they have to be unique, and why do they have to be unique? Also, there might be better alternatives to #define ... but death can probably give a better explanation than I can ;)



more "global" the better.  Well i just need some constant, like for example WM_CREATE and such in my application  and since I'm going to have o lot of them i don't want to specify all the numbers by myself since it's more work and more error prone (duplicated constant). So since i don't care what the number is i just want it to be unique compared to other #define or group of #define .
Posted on 2005-07-11 18:10:52 by AceEmbler
Maybe using an enumeration is a good solution? If not, why? Be more specific.
Posted on 2005-07-11 18:16:13 by death
Well, window messages generally only have to be unique for each control, so if you're doing custom controls, you don't have to worry that much - start each control messages at WM_USER + 0x100 or whatever.

If you need global window messages, the same applies but at a process level (be careful with HWND_BROADCAST though - best to avoid it).

If you have other requirements, another solution might be needed.
Posted on 2005-07-11 18:16:58 by f0dder
enumeration is bad for what i need. And even with enumeration i need unique numbers. And my problem does not have anything with ms windows. I just want to make some "state" constants so it does not matter what number is hidden  under alias.
Posted on 2005-07-12 17:40:02 by AceEmbler
On post-build step, execute a little proggie to write into a .h file a "#define MYVAL %rand", where replace %rand with the return value of GetTickCount.
This way, a new number will be defined for the next time you compile. Include the .h file in as few files as possible - VS will recompile them on every build of the project, since that .h file will have been modified, and .c/.cpp files will have dependency on it.
Posted on 2005-07-12 20:00:26 by Ultrano

enumeration is bad for what i need. And even with enumeration i need unique numbers. And my problem does not have anything with ms windows. I just want to make some "state" constants so it does not matter what number is hidden? under alias.


Why is enum bad? You can always set a value for the first enumeration constant.

enum x_state { first_state = 35, second_state, last_state };


There is no static way to ensure unique numbers among multiple "enumeration" types. You can dynamically create unique numbers with a "get new number" routine. Or use a preprocessor (the C preprocessor is not powerful enough - it lacks macro variables).
Posted on 2005-07-13 15:52:33 by tenkey
I didn't know that you can specify no value for enum variables.  It looks like enum can be more usefull. But still it's far from ideal.Ii cannot diffuse it on a different source codes. And i will have to specify the type of variable in some parts of a code.

But i will try it.
Posted on 2005-07-14 12:40:53 by AceEmbler
what's wrong with using GUID's if they really need to be unique accross enums?
Posted on 2005-07-17 09:09:17 by grv575