[PATCH:makedepend] Use do { ... } while(0) idiom to make debug() macro safer

Jasper St. Pierre jstpierre at mecheye.net
Sat Mar 12 19:35:00 UTC 2016


"Safe multi-line macros" have been suggested before, and turned down.
The C extension that gcc supports is statement expressions:
https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html

On Sat, Mar 12, 2016 at 11:15 AM, walter harms <wharms at bfs.de> wrote:
>
>
> Am 12.03.2016 19:43, schrieb Matt Turner:
>> On Sat, Mar 12, 2016 at 10:24 AM, walter harms <wharms at bfs.de> wrote:
>>>
>>>
>>> Am 12.03.2016 19:15, schrieb Alan Coopersmith:
>>>> Cleans up several -Wempty-body warnings from gcc 5.3
>>>>
>>>> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
>>>> ---
>>>>  def.h | 4 ++--
>>>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/def.h b/def.h
>>>> index 1930cde..59670a9 100644
>>>> --- a/def.h
>>>> +++ b/def.h
>>>> @@ -82,9 +82,9 @@ extern int  _debugmask;
>>>>   *     3     show #include SYMBOL
>>>>   *     4-6   unused
>>>>   */
>>>> -#define debug(level,arg) { if (_debugmask & (1 << level)) warning arg; }
>>>> +#define debug(level,arg) do { if (_debugmask & (1 << level)) warning arg; } while(0)
>>>>  #else
>>>> -#define      debug(level,arg) /**/
>>>> +#define      debug(level,arg) do { /**/ } while (0)
>>>>  #endif /* DEBUG */
>>>>
>>>>  typedef      unsigned char boolean;
>>>
>>>
>>>  #define        debug(level,arg)   while(0)
>>>
>>> should be sufficient (not tested)
>>
>> Maybe, but that sure looks strange to my eye, while the do { ... }
>> while(0) pattern is well recognized.
>
> for me other way around :)
>
> never mind, both are a noop, someone could propose this as C extension ,)
>
> re,
>  wh
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: https://lists.x.org/mailman/listinfo/xorg-devel



-- 
  Jasper


More information about the xorg-devel mailing list