|
-
August 30th, 2007, 02:16 PM
#1
Strange macro, valid?
In a header I was looking at, I saw this...
Code:
#define MMM_X(x)_Z(z) (0x0C + (((x)-1)*3 + ((z)-1))*4)
... is that valid? I don't recall seeing a macro like that before.
(Name changed to protect the innocent!!!)
Last edited by Exit; September 1st, 2007 at 05:35 AM.
-
September 1st, 2007, 03:32 AM
#2
Re: Strange macro, valid?
That looks wrong to me. Where did you find it?
-
September 1st, 2007, 03:36 AM
#3
Re: Strange macro, valid?
-
September 1st, 2007, 03:49 AM
#4
Re: Strange macro, valid?
In a buildroot kernel header for a KS8695 chip.
-
September 1st, 2007, 05:10 AM
#5
Re: Strange macro, valid?
 Originally Posted by Mitsukai
looks fine for me
Why does it appear fine to you
Preprocessing directive are of the form
Code:
# define identifier replacement-list new-line
which defines an object-like macro that causes each subsequent instance of the macro name.
or
Code:
# define identifier lparen identifier-listopt ) replacement-list new-line
which defines a function-like macro with parameters, similar syntactically to a function call.
Last edited by sunnypalsingh; September 1st, 2007 at 05:15 AM.
Appreciate others by rating good posts
"Only buy something that you'd be perfectly happy to hold if the market shut down for 10 years." - Warren Buffett
-
September 1st, 2007, 06:04 AM
#6
Re: Strange macro, valid?
the macro is FINE
the information by the OP is NOT
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);
}
note _Z could also be a type or function!
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.
Last edited by Mitsukai; September 1st, 2007 at 06:08 AM.
-
September 1st, 2007, 06:38 AM
#7
Re: Strange macro, valid?
the information by the OP is NOT
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.
Last edited by Exit; September 1st, 2007 at 06:52 AM.
Reason: Spelling mistake.
-
September 1st, 2007, 06:56 AM
#8
Re: Strange macro, valid?
this is not a compilable example so the information by OP is not enough
-
September 1st, 2007, 06:57 AM
#9
Re: Strange macro, valid?
 Originally Posted by Mitsukai
the macro is FINE
It looks wrong to me. 
Can you think of a sensible use which does not result in a 'redundant operation' warning ?
-
September 1st, 2007, 06:59 AM
#10
Re: Strange macro, valid?
redundant operation?
just put int x = infront of the macro call 
or make _Z a function or type
-
September 1st, 2007, 09:24 AM
#11
Re: Strange macro, valid?
 Originally Posted by Mitsukai
redundant operation?
just put int x = infront of the macro call 
Good point.
Nevertheless, the macro still looks wrong to me.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|