lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sun, Jan 25, 2015 at 11:21:45PM -0600, Paige DePol wrote:
> Niccolo Medici <niccolomedici@gmail.com> wrote:
> 
> > 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:
> 
> Sorry, it was late and I was just heading to bed, I missed the part of
> your original post that mentioned the macro parameter were separated by
> commas... I thought you were just asking a general question about
> bracketed macro parameters! ;)
> 

The macro arguments might themselves be comma expressions. So the
parentheses aren't useless.

(Sorry. I deleted the previous posts in this thread so couldn't reply to it.
The comma expression case just occurred to me.)