|
In the following macro Name refers to something outside of the definition:
#define TestAndClearDirty(ni) \
test_and_clear(ni, Name)
But if Name does not exist in that source module, or is not externalised in a linked module it will never work. My suspicion is that this macro is wrong and Name should be one of the formal parameters, and refer to one of the flags in the ni struct. Something like:
#define TestAndClearDirty(ni, Name) \
test_and_clear(ni, Name)
And it would be called by
TestAndClearDirty(ni, some_falg_name);
But I am working completely in the dark and making (probably wild) guesses.
I can only suggest that you go back to the place or person that this code comes from for assistance.
|
|
|
|
|
I have discovered something: if I write:
TestAndClearDirty(ni);
everything is ok. But if I write:
BOOL b = TestAndClearDirty(ni);
I get errors:
error C2552: 'b' : non-aggregates cannot be initialized with initializer list
error C2143: syntax error : missing '}' before 'const'
error C2143: syntax error : missing ';' before 'const'
error C2143: syntax error : missing ';' before 'const'
error C2065: 'old_state' : undeclared identifier
See first post for original definition ... I hope I can make it ...
P.S. Why I written BOOL b = ... ? Because that function, TestAndClearDirty , is used inside some if condition ...
|
|
|
|
|
Once again there is considerable context missing. And it seems you have also removed all the macro definitions from your earlier post.
|
|
|
|
|
test_and_clear is a macro you can't use it as a function, macros don't return things without hijinx
GCC has a thing called a statement expression
Using the GNU Compiler Collection (GCC): Statement Exprs[^]
However I strong suggestly you don't do it just create a proper function (that is after all what you are trying to write) and inline it if speed is an issue.
In vino veritas
|
|
|
|
|
_Flaviu wrote:
How to get rid of this error ? Anytime you are having preprocessor troubles, the only solution is to send the output of the preprocessor to a text file using the /P compiler switch. Only then will you be able to see what exactly is being sent through the compiler.
See here for more.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
When you have so many nested macros, one thing to do is look at a pre-processed version of the code.
In MSVC, adding /P to the command line will create a file with a .i extension, containing the pre-processed code. Examining that will probably give you the cause of the error.
EDIT: I see someone beat me to giving the same advice.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
I have put that option on property page settings and show me no more details: The error occur in some inode.cpp file (ex C file), and those macros are some support.h file.
So, when I compiled with /P option, I got only inode.i file, where I have a line:
#line 1 "d:\\project\\.......\\inode.cpp"
that is all. And support.i doesn't generated, due to error:
fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
...
fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
...
fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
...
The problem is that macro TestAndClearDirty(ni); is
|
|
|
|
|
I have put that option on property page settings and show me no more details: The error occur in inode.cpp file (former inode.c file), and those macros are in support.h file.
So, when I compiled with /P option, I got only inode.i file, where I have a line:
#line 1 "d:\\project\\.......\\inode.cpp"
that is all. And support.i doesn't generated, due to error:
fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
...
fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
...
fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
...
The problem is the code is trying to use TestAndClearDirty(ni); for returning BOOL value, and I don't think that macro is written to return a BOOL value ... I guess from here is coming these errors ...
modified 14-Oct-19 4:54am.
|
|
|
|
|
This question is somewhat related to the question Passing a "value", that was either #defined or #undef, into a macro and check if it was defined? - C / C++ / MFC Discussion Boards[^] , but the core question in this thread is quite different than that of the other thread so I think this should be a separate thread. In the other thread I was looking to have a macro do my checks, but it would be ok to do it without a macro as well. The important thing is that the checks (there are several hundreds of them) are nicely formatted in way that makes it easy to read. So, is it possible to achieve something like this with some clever workaround:
#if defined(ADDR1) && defined(ADDR2) _Static_assert(ADDR1==ADDR2, #ADDR1 " is not equal to " #ADDR2); #endif
#if defined(ADDR3) && defined(ADDR4) _Static_assert(ADDR3==ADDR4, #ADDR3 " is not equal to " #ADDR4); #endif
#if defined(ADDR5) && defined(ADDR6) _Static_assert(ADDR5==ADDR6, #ADDR5 " is not equal to " #ADDR6); #endif
#if defined(ADDR7) && defined(ADDR8) _Static_assert(ADDR7==ADDR8, #ADDR7 " is not equal to " #ADDR8); #endif As you can see, the "correct" way of doing this (the way the compiler wants it) is not easy to read at all (and not so easy to generate in Excel or edit using the block caret feature in Eclipse):
#if defined(ADDR1) && defined(ADDR2)
_Static_assert(ADDR1 == ADDR2, #ADDR1 " is not equal to " #ADDR2);
#endif
#if defined(ADDR3) && defined(ADDR4)
_Static_assert(ADDR3 == ADDR4, #ADDR3 " is not equal to " #ADDR4);
#endif
#if defined(ADDR5) && defined(ADDR6)
_Static_assert(ADDR5 == ADDR6, #ADDR5 " is not equal to " #ADDR6);
#endif
#if defined(ADDR7) && defined(ADDR8)
_Static_assert(ADDR7 == ADDR8, #ADDR7 " is not equal to " #ADDR8);
#endif Can anyone think of a neat trick? Maybe something involving #include files? I think I've read somewhere that you can have several #include on the same line.
modified 9-Oct-19 18:19pm.
|
|
|
|
|
What problem are you actually trying to resolve? The requirement for hundreds of #defines suggests something in your design needs looking at.
|
|
|
|
|
|
I don't see the problem. Use the same defined name in all your code, then you do not need to care. If it's not defined then the compiler will complain.
|
|
|
|
|
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.
|
|
|
|
|
Yes, if worse comes to worse I will do this. Is there source code available somewhere for a "preprocessor light" that can automatically detect #defines that are evaluated to numbers?
|
|
|
|
|
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?
modified 9-Oct-19 13:23pm.
|
|
|
|
|
Member 12661464 wrote: Any idea what it might be? Maybe the Window is not getting refreshed properly. Do you have code that is controlling when the icon gets painted?
|
|
|
|
|
I just put the following code in the OnPaint () handler.
CPaintDC dc(this);
CDC *psrcDC = m_PictureControl.GetDC();
CDC dstDC;
dstDC.CreateCompatibleDC(psrcDC);
HBITMAP oldBmp = (HBITMAP)SelectObject(dstDC.m_hDC, startBitmap);
BLENDFUNCTION blend = { AC_SRC_OVER, 0,255, AC_SRC_ALPHA };
AlphaBlend(psrcDC->m_hDC, 0, 0, iWidth, iHeight, dstDC.m_hDC,0, 0, iWidth, iHeight, blend);
DeleteObject(oldBmp);
DeleteObject(startBitmap);
ReleaseDC(psrcDC);
|
|
|
|
|
Sorry, I cannot see anything obvious. Also, I am afraid I don't use MFC, so cannot try a similar test.
|
|
|
|
|
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:
#define VALIDATE_ADDR_IF_THEY_BOTH_EXIST(ADDR1,ADDR2) \
#if defined(ADDR1) && defined(ADDR2) \
VALIDATE_ADDR(ADDR1, ADDR2) \
#endif 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)
#ifdef MY_ADDR_4
#undef MY_ADDR_4
#endif
VALIDATE_ADDR_IF_THEY_BOTH_EXIST(MY_ADDR_1, MY_ADDR_2); VALIDATE_ADDR_IF_THEY_BOTH_EXIST(MY_ADDR_3, MY_ADDR_4);
|
|
|
|
|
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.
|
|
|
|
|
Macros are purely compile time. If you want runtime checks then use functions. Macros such as the above tend to be more trouble than they are worth.
|
|
|
|