I'm using visual studio how can i create unique numbers for my #define statements ??
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 ;)
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 .
Maybe using an enumeration is a good solution? If not, why? Be more specific.
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.
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.
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.
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.
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.
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).
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.
But i will try it.
what's wrong with using GUID's if they really need to be unique accross enums?