Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: va_start without the first argument? Date: Tue, 14 Mar 2017 11:34:42 -0700 Organization: None to speak of Lines: 42 Message-ID: References: <7fda2e02-9a6a-411f-9d91-1ad9030ec778@googlegroups.com> <7dc37a16-7135-4e50-accf-591c923908c4@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="68145e82dff5cec9d4077a7833a68c0b"; logging-data="29072"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Tz73EF3RxGMO0DF+jghSJ" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:jxLONEn04QebKv+g5C7IZl525Xs= sha1:2fmjrJg7FPfpQuuG8SMMeoSRwgY= Xref: csiph.com comp.lang.c:106067 scott@slp53.sl.home (Scott Lurndal) writes: > Keith Thompson writes: >>David Brown writes: >>[...] >>> #ifdef __GNUC__ >>> #define IS_COMPILE_TIME_CONSTANT(x) __builtin_constant_p(x) >> >>I'd parenthesize this: >> >>#define IS_COMPILE_TIME_CONSTANT(x) (__builtin_constant_p(x)) >> >>I'm not sure whether it can make a difference, but it's easier to add >>the parentheses than to prove that they're not needed. > > I think if you are adding additional parenthesis, I'd be tempted to write it: > > #define IS_COMPILE_TIME_CONSTANT(x) __builtin_constant_p((x)) Why? In both David's version and mine, the reference to x in the macro definition is already parenthesized. The fact that the parentheses are for a function call (or macro invocation?) rather than grouping doesn't matter as far as operator precedence is concerned. Similarly, if a macro definition uses an argument as an array index, it's already surrounded by [] so it doesn't need additional (). In general, for a macro whose arguments are expressions and that expands to an expression, each reference to each argument should be parenthesized, and the entire definition should also be parenthesized. Thus: #define ADD(x, y) ((x) + (y)) But: #define INDEX(a, i) ((a)[i]) // no need for additional parentheses on i -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"