If I use the same defines both in my local code and in the shared h-file then I get compiler warnings, "REGISTER_NAME" redefined. I need to include the shared h-file in my own project as well because in addition to addresses, it also contains structs and enums that contains information about what the data in the different registers mean. If I get rid of my local file (the comprehensive file with ALL register addresses) then I expose all the registers and I don't want that, I only want to expose a subset. Maybe I should move my structs and enums to a separate shared h-file and ensure that (through special inclusion guards) my local and the shared h-file are never included into the same file, but I would prefer to keep everything (addresses, structs and enums) in the same file.
You can use #define statements in each source module to include only certain sections of the headers, which is the standard way of doing it. Take a look at any of the Windows header files and you will see examples.
The registers that should be exposed are not contiguous, they appear quite randomly in the address space. Currently, they are ordered in ascending order of the address and it's too late in the development phase to re-number the addresses according to whether they are exposed or not. So, adding a lot of #ifdefs would pollute the code quite a bit and make it much harder to read. I'm a firm believer in having code that easy to read for the human eye.
As an alternative, you could automatically generate (e.g. pre-build step) both the correct header and its pretty representation (e.g. human readable file) starting from a sigle configuration file.
I use a similar approach to share constant values in both C and Lua programs.
Very probably there is, but, unfortunately, I am not aware of. I do use a little Lua script for the purpose. Lua features powerful string manipulation functions and it is a very enjoyable scripting language. You might also use a more popular scripting language, like, for instance, Python (another option is, if you like it, using the C++ 11 regex classes).
I display the 32 bit icon with transparency using the AlphaBlend function. If the window with the icon is moved partially outside the monitor screen, the transparent area in some places is filled. Damaged places with partial transparency.. Any idea what it might be?
I want to create a macro that is fully executed at compile time (not runtime). If two values are both defined, then I want to check if they are equal. If at least one of them is not defined, then nothing should happen. I have come halfway, the following works great:
#define VALIDATE_ADDR(ADDR1,ADDR2) _Static_assert(ADDR1 == ADDR2, #ADDR1 " is not equal to " #ADDR2);
However, when I try to nest that macro into another macro, then I run into trouble:
Can someone please help me so I can do checks like this:
#define MY_ADDR_1 (1)
#define MY_ADDR_2 (2)
#define MY_ADDR_3 (3)
VALIDATE_ADDR_IF_THEY_BOTH_EXIST(MY_ADDR_1, MY_ADDR_2); // Compile time error since MY_ADDR_1 != MY_ADDR_2
VALIDATE_ADDR_IF_THEY_BOTH_EXIST(MY_ADDR_3, MY_ADDR_4); // Compiles just fine since MY_ADDR_4 is not defined
AFAIK, that's not possible, since the # token is reserved for stringifying macro parameters within the macro expansion.
Also, I see that your definition for VALIDATE_ADDR ends in a semicolon. In general, you do not want to end a macro with a semicolon, since this can lead to, in the best case, a compiler error, and in the worst case, a subtle and hard to find bug.
What do you mean? I've clearly stated I want compile time execution, not runtime execution of this macro. Are you thinking of the _Static_assert function? It is executed at compile time, I think it's a feature built into the gcc compiler.