Velocity Reviews > Difference between a MACRO and a FUNCTION

# Difference between a MACRO and a FUNCTION

Richard Tobin
Guest
Posts: n/a

 09-20-2007
In article <fcujr8\$95c\$(E-Mail Removed)1.ov.home.nl>,
\$)CHarald van D )& k <(E-Mail Removed)> wrote:

>The relevant rules from the grammar are:
>
>primary-expression:
> ( expression )
>
>conditional-expression:
> logical-OR-expression ? expression : conditional-expression
>
>Assuming a is an expression, it is valid in both forms.

Yes. For it to break when the parenthesized version works, there
would have to be something that is parsable as an expression when
parenthesized, but not otherwise. All parentheses do is turn an
expression into a primary-expression, so if parentheses make it
an expression it already was one.

[We can see that parentheses are needed for the third operand, since
there *are* things that are parsable as a conditional-expression when
parenthesized, but not otherwise: a=b for example.]

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.

Army1987
Guest
Posts: n/a

 09-20-2007
On Thu, 20 Sep 2007 19:46:47 +0000, Richard Heathfield wrote:

> Keith Thompson said:
>
>> I have a
>> nagging hunch that there *might* be an argument that would break the
>> first form, perhaps something involving the ?: operator in the operand
>> itself.

>
> That was my principal method of attack. I couldn't break it that way, but
> that doesn't mean it can't be broken. (Nor does it mean it can,
> obviously.)
>
> I suspect that a grammatical analysis will bear more fruit than any number
> of attempts at a crack.

Given the syntax and the fact that the only place where the token
? and the token : can occur is a conditional expression, adding
( after ?, or ) before :, should be no more useful that adding
( after [, or ) before ].
Compare:

Syntax
1 postﬁx-expression:
primary-expression
postﬁx-expression [ expression ]
<snip>

and:

Syntax
1 conditional-expression:
logical-OR-expression
logical-OR-expression ? expression : conditional-expression

(Yes, there could be some mysterious, hidden point that I'm
missing, considering that I was almost as self-assured as now when
I claimed that #define INT_MIN -128 couldn't possibly be broken.)
--
Army1987 (Replace "NOSPAM" with "email")
If you're sending e-mail from a Windows machine, turn off Microsoft's
stupid “Smart Quotes” feature. This is so you'll avoid sprinkling garbage
characters through your mail. -- Eric S. Raymond and Rick Moen