|
You are welcome. It always pays to check the documentation first.
|
|
|
|
|
I come back for another strange error (for me is strange ):
error C2143: syntax error : missing ')' before '{'
And the lin with error is:
TestAndClearDirty(ni);
and TestAndClearDirty is declared as:
#define TestAndClearDirty(ni) \
test_and_clear(ni, Name)
where test_and_clear(ni, Name) is defined as:
#define test_and_clear(ni, flag) \
test_and_clear_bit(NI_##flag, (ni)->state)
and clear_bit is declared as:
#define test_and_clear_bit(bit, var) \
({ \
const BOOL old_state = test_bit(bit, var); \
clear_bit(bit, var); \
old_state; \
})
How to get rid of this error ?
modified 10-Oct-19 12:11pm.
|
|
|
|
|
Once again there is information missing. I have tried putting those definitions in the correct order and compiling but it produces too many errors and unknown names.
|
|
|
|
|
You might try to get rid of those ugly macros (you are using C++, right?).
|
|
|
|
|
In fact is a C code which I try to convert to C++. I will try to call directly these functions ... I guess that you said, I am right ?
|
|
|
|
|
Yes, but I don't know if I can, because from step TestAndClearDirty(ni); to test_and_clear(ni, Name) , the second paramter is missing (see the first post).
Moreover, at step test_and_clear_bit(NI_##flag, (ni)->state) what is the first parameter ?
modified 11-Oct-19 6:44am.
|
|
|
|
|
That is exactly the problem. We do not have that information and you are not providing it.
|
|
|
|
|
Believe me, I haven't extra information, for instance, at step test_and_clear(ni, Name) , when I try to go to definition of Name , VS editor goes nowhere, searched globally in the whole project, found nothing, and searched in the entire project folder with the external file seeker, found no defintion of this Name parameter ...
|
|
|
|
|
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?
|
|
|
|