>I am not convinced that what this testcase expects is LRM-specified
>behavior.
Right. I would like the behavior to match the C
preprocessor, but did not mean to imply that what I want was
already LRM specified.
>Personally I would have written:
>
>`define REPEAT(n, d) `REPEAT_``n(d)
>
>since that clearly forms the REPEAT_n macro's
>name (during substitution of n) before invoking it.
Fair enough, that's my C habits showing through, although it
shouldn't change the results. The LRM says outer levels are
always expanded first, so using CONCAT or not shouldn't matter.
>The LRM is not specific about whether the (first) actual
>argument (to `CONCAT) below should be expanded before it is
>substituted or after.
Here's an example to disect further. The VALUEb one seems
to fail on (I suspect) every simulator.
`define ZERO_0 "0"
`define CONCAT(a, b) a``b
`define NOTNOT(a) a
`define VALUEa(a) `CONCAT(`ZERO_,a)
`define VALUEb(a) `CONCAT(`ZERO_,`NOTNOT(a))
module t;
initial begin
`define CNT 0
// Works on at least one
$write("EXP: '0' GOT '"); $write(`VALUEa(`CNT)); $write("'\n");
// Fails on the one that DOES work
$write("EXP: '0' GOT '"); $write(`VALUEb(`CNT)); $write("'\n");
end
endmodule
Follwing the `VALUEb expansion, I would like the LRM to require:
`VALUEb(`CNT) // LRM: outer first
`CONCAT(`ZERO_,`NOTNOT(`CNT)) // LRM: outer first
`ZERO_```NOTNOT(`CNT) // See below
`ZERO_``CNT // Same rule as above
`ZERO_``0 // LRM: Normal `` expansion
`ZERO_0 // LRM: Normal expansion
"0"
I suspect VCS (naming names, since they did the best across
the survey) is doing this:
`VALUEb(`CNT) // LRM: outer first
`CONCAT(`ZERO_,`NOTNOT(`CNT)) // LRM: outer first
`ZERO_```NOTNOT(`CNT) // `` collapses without whitespace
`ZERO_`NOTNOT(`CNT) // NOTNOT expands and adds whitespace
`ZERO_ `CNT // Extra space now in the token
`ZERO_ 0 // Extra space now in the token
[Does anyone know a workaround to get the behavior I would
like?]
The question is what does `` imply as to expanding any macro
on its LHS or RHS? I think the LRM is silent on this, but
propse that `` occurs after complete expansions macros on
either side of it. (Note the alternative, that `` occurs
"first" results in the extra space as shown above, which I
don't see how would be useful?)
I would also propose the LRM to say that `` collapses
whitespace on both sides to match C99. It now says "without
introducing white space" which is not sufficient if a space
was mis-introduced into a define value, possibly from an
earlier substitution.
-Wilson
-- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.Received on Tue Jun 22 19:30:21 2010
This archive was generated by hypermail 2.1.8 : Tue Jun 22 2010 - 19:33:10 PDT