In a header I was looking at, I saw this...
... is that valid? I don't recall seeing a macro like that before.Code:#define MMM_X(x)_Z(z) (0x0C + (((x)-1)*3 + ((z)-1))*4)
(Name changed to protect the innocent!!!)
Printable View
In a header I was looking at, I saw this...
... is that valid? I don't recall seeing a macro like that before.Code:#define MMM_X(x)_Z(z) (0x0C + (((x)-1)*3 + ((z)-1))*4)
(Name changed to protect the innocent!!!)
That looks wrong to me. Where did you find it?
looks fine for me
In a buildroot kernel header for a KS8695 chip.Quote:
Where did you find it?
Why does it appear fine to you :eek:Quote:
Originally Posted by Mitsukai
Preprocessing directive are of the form
which defines an object-like macro that causes each subsequent instance of the macro name.Code:# define identifier replacement-list new-line
or
which defines a function-like macro with parameters, similar syntactically to a function call.Code:# define identifier lparen identifier-listopt ) replacement-list new-line
the macro is FINE
the information by the OP is NOT
note _Z could also be a type or function!Code:#define _Z(z) (z)+
#define MMM_X(x)_Z(z) (0x0C + (((x)-1)*3 + ((z)-1))*4)
int main()
{
int z = 5;
MMM_X(5);
}
Code:Your Comeau C/C++ test results are as follows:
Comeau C/C++ 4.3.9 (Mar 27 2007 17:24:47) for ONLINE_EVALUATION_BETA1
Copyright 1988-2007 Comeau Computing. All rights reserved.
MODE:strict errors C++ noC++0x_extensions
"ComeauTest.c", line 8: warning: expression has no effect
MMM_X(5);
^
In strict mode, without -tused, Compile succeeded (but remember, the Comeau online compiler does not link).
Compiled with C++0x extensions DISabled.
What, pray tell, is wrong with the information in the OP? The macro appears in the header as is, (with a different name), and is the only macro in the header. All the other #defines are constant base addresses, register offsets and bit masks.Quote:
the information by the OP is NOT
this is not a compilable example so the information by OP is not enough
It looks wrong to me. ;)Quote:
Originally Posted by Mitsukai
Can you think of a sensible use which does not result in a 'redundant operation' warning ?
redundant operation?
just put int x = infront of the macro call ;)
or make _Z a function or type
Good point.Quote:
Originally Posted by Mitsukai
:o
Nevertheless, the macro still looks wrong to me.
:D