Re: [Qemu-devel] [PATCH v2 13/18] nvdimm: build namespace config data
On 08/28/2015 07:59 PM, Stefan Hajnoczi wrote: On Wed, Aug 26, 2015 at 06:42:01PM +0800, Xiao Guangrong wrote: On 08/26/2015 12:16 AM, Stefan Hajnoczi wrote: On Fri, Aug 14, 2015 at 10:52:06PM +0800, Xiao Guangrong wrote: +#ifdef NVDIMM_DEBUG +#define nvdebug(fmt, ...) fprintf(stderr, "nvdimm: " fmt, ## __VA_ARGS__) +#else +#define nvdebug(...) +#endif The following allows the compiler to check format strings and syntax check the argument expressions: #define NVDIMM_DEBUG 0 /* set to 1 for debug output */ #define nvdebug(fmt, ...) \ if (NVDIMM_DEBUG) { \ fprintf(stderr, "nvdimm: " fmt, ## __VA_ARGS__); \ } This approach avoids bitrot (e.g. debug format string arguments have become outdated). Really good tips, thanks for your sharing. I forgot the do { ... } while (0) in the macro to make nvdebug("hello world"); work like a normal C statement. Got it, will keep it in my mind. -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [Qemu-devel] [PATCH v2 13/18] nvdimm: build namespace config data
On Wed, Aug 26, 2015 at 06:42:01PM +0800, Xiao Guangrong wrote: On 08/26/2015 12:16 AM, Stefan Hajnoczi wrote: On Fri, Aug 14, 2015 at 10:52:06PM +0800, Xiao Guangrong wrote: +#ifdef NVDIMM_DEBUG +#define nvdebug(fmt, ...) fprintf(stderr, nvdimm: fmt, ## __VA_ARGS__) +#else +#define nvdebug(...) +#endif The following allows the compiler to check format strings and syntax check the argument expressions: #define NVDIMM_DEBUG 0 /* set to 1 for debug output */ #define nvdebug(fmt, ...) \ if (NVDIMM_DEBUG) { \ fprintf(stderr, nvdimm: fmt, ## __VA_ARGS__); \ } This approach avoids bitrot (e.g. debug format string arguments have become outdated). Really good tips, thanks for your sharing. I forgot the do { ... } while (0) in the macro to make nvdebug(hello world); work like a normal C statement. -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [Qemu-devel] [PATCH v2 13/18] nvdimm: build namespace config data
On 08/26/2015 12:16 AM, Stefan Hajnoczi wrote: On Fri, Aug 14, 2015 at 10:52:06PM +0800, Xiao Guangrong wrote: +#ifdef NVDIMM_DEBUG +#define nvdebug(fmt, ...) fprintf(stderr, nvdimm: fmt, ## __VA_ARGS__) +#else +#define nvdebug(...) +#endif The following allows the compiler to check format strings and syntax check the argument expressions: #define NVDIMM_DEBUG 0 /* set to 1 for debug output */ #define nvdebug(fmt, ...) \ if (NVDIMM_DEBUG) { \ fprintf(stderr, nvdimm: fmt, ## __VA_ARGS__); \ } This approach avoids bitrot (e.g. debug format string arguments have become outdated). Really good tips, thanks for your sharing. -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [Qemu-devel] [PATCH v2 13/18] nvdimm: build namespace config data
On Fri, Aug 14, 2015 at 10:52:06PM +0800, Xiao Guangrong wrote: +#ifdef NVDIMM_DEBUG +#define nvdebug(fmt, ...) fprintf(stderr, nvdimm: fmt, ## __VA_ARGS__) +#else +#define nvdebug(...) +#endif The following allows the compiler to check format strings and syntax check the argument expressions: #define NVDIMM_DEBUG 0 /* set to 1 for debug output */ #define nvdebug(fmt, ...) \ if (NVDIMM_DEBUG) { \ fprintf(stderr, nvdimm: fmt, ## __VA_ARGS__); \ } This approach avoids bitrot (e.g. debug format string arguments have become outdated). -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html