Received: from eggs.gnu.org ([2001:4830:134:3::10]:52408) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1akBhz-0002x8-Gx for qemu-devel@nongnu.org; Sun, 27 Mar 2016 10:30:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1akBhv-0005Zn-9H for qemu-devel@nongnu.org; Sun, 27 Mar 2016 10:30:27 -0400 Received: from mail-ig0-x244.google.com ([2607:f8b0:4001:c05::244]:33990) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1akBhv-0005Zj-3E for qemu-devel@nongnu.org; Sun, 27 Mar 2016 10:30:23 -0400 Received: by mail-ig0-x244.google.com with SMTP id av4so6904763igc.1 for ; Sun, 27 Mar 2016 07:30:22 -0700 (PDT) Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=iso-8859-1 From: Programmingkid In-Reply-To: <87io09viom.fsf@linaro.org> Date: Sun, 27 Mar 2016 10:30:20 -0400 Content-Transfer-Encoding: quoted-printable Message-Id: <07F76AB3-B15E-4852-9F2E-92A9EC71C2F6@gmail.com> References: <7A168ABF-EB8A-43E5-9821-F4D8AD9B6E53@gmail.com> <87io09viom.fsf@linaro.org> Subject: Re: [Qemu-devel] [PATCH 3/3] hid.c: Add debug support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?iso-8859-1?Q?Alex_Benn=E9e?= Cc: Peter Maydell , Gerd Hoffmann , qemu-devel qemu-devel On Mar 26, 2016, at 2:48 AM, Alex Benn=E9e wrote: >=20 > Programmingkid writes: >=20 >> Add debug macros to the code for easier debugging. >>=20 >> Signed-off-by: John Arbuckle >> --- >> hw/input/hid.c | 11 +++++++++++ >> 1 file changed, 11 insertions(+) >>=20 >> diff --git a/hw/input/hid.c b/hw/input/hid.c >> index 329a27b..42ca592 100644 >> --- a/hw/input/hid.c >> +++ b/hw/input/hid.c >> @@ -37,6 +37,13 @@ >> #define RELEASED -1 >> #define PUSHED -2 >>=20 >> +/* #define DEBUG_HID_CODE */ >> +#ifdef DEBUG_HID_CODE >> + #define DEBUG_HID(fmt, ...) printf(fmt, __VA_ARGS__) >> +#else >> + #define DEBUG_HID(fmt, ...) (void)0 >> +#endif >> + >=20 > This style of debug setup is discouraged these days as its prone to > bitrot. It's better to define like this: >=20 > #define DEBUG_HID(fmt, ...) \ > if (DEBUG_HID_CODE) { \ > printf(fmt, __VA_ARGS);\ > } >=20 > This means you get the benefit of the compiler checking your format > strings even if the code gets optimised away when DEBUG_HID_CODE isn't > defined. I don't like if conditions in the debug macro because they do take up = cpu time. The (void)0 is just zero. I don't think it would take any cpu = time away from the program.=20=