[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: What's the purpose of these parentheses in the #define's?
- From: Niccolo Medici <niccolomedici@...>
- Date: Sun, 25 Jan 2015 22:17:18 +0200
On 1/25/15, Paige DePol <lual@serfnet.org> wrote:
> Niccolo Medici <niccolomedici@gmail.com> wrote:
>
>> lauxlib.h has:
>>
>> #define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
>> #define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
>>
>> Why are there "(n)" / "(d)" / "(i)" instead of "n" / "d" / "i"? There
>> are commas around these letters so there shouldn't be a potential
>> precedence problem there, or am I wrong?
[...]
>
> I can explain this best with a simple example:
>
> #define ackoop(a) a * 20
>
> ackoop(5 + 7)
>
> This would expand to:
>
> 5 + 7 * 20
Yes, I know about *that*. But the macros I'm talking about look like
function calls. A comma (,) has the lowest precedence in C. So why do
we need the parentheses? Let me modify your example:
#define ackoop(a, b) boop(a, b)
If I do:
ackoop(5 + 7, -6)
Everything works alright. No need for further parentheses in the macro
definition. My question is, why is the macro nevertheless defined as:
#define ackoop(a, b) boop((a), (b))
Why's the need for these seemingly spurious parentheses in Lua's macros?