From 0a26bd74e1800a748c24cb24c0bd77abd3fa17dc Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Mon, 22 Jul 2013 07:12:15 +0000 Subject: [PATCH] Replace the type-checking COMPTR macro with my current idea of best practice in type-check macros. [originally from svn r9963] --- windows/winjump.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/windows/winjump.c b/windows/winjump.c index abefe445..f674133b 100644 --- a/windows/winjump.c +++ b/windows/winjump.c @@ -353,12 +353,12 @@ static const PROPERTYKEY PKEY_Title = { 0x00000002 }; -/* Type-checking macro to provide arguments for CoCreateInstance() etc. - * The pointer arithmetic is a compile-time pointer type check that 'obj' - * really is a 'type **', but is intended to have no effect at runtime. */ +/* Type-checking macro to provide arguments for CoCreateInstance() + * etc, ensuring that 'obj' really is a 'type **'. */ +#define typecheck(checkexpr, result) \ + (sizeof(checkexpr) ? (result) : (result)) #define COMPTR(type, obj) &IID_##type, \ - (void **)(void *)((obj) + (sizeof((obj)-(type **)(obj))) \ - - (sizeof((obj)-(type **)(obj)))) + typecheck((obj)-(type **)(obj), (void **)(void *)(obj)) static char putty_path[2048]; -- 2.45.2