[1] The local warning suppression added to the macro does not work as the warning suppression is effected only after the complier encounter the first curly brace "{" (which does not appear in this specific MACRO) #define OBJECT_OFFSETOF(OBJECT, MEMBER) __pragma(warning(push) __pragma(warning(disable:4700)) ((char *)&(OBJECT)->MEMBER - (char *)(OBJECT)) __pragma(warning(push)
[2] The usage of the decltype does work with of a built in VS project I created: #define OBJECT_OFFSETOF(OBJECT, MEMBER) \ ((LONG)(LONG_PTR)&((decltype(OBJECT))0)->MEMBER) I think it is the right way to implement it. But, this keyword "decltype" is ignored by the compiler when above macro is used in the OVS source base. I don't know the reason for it but it might be related to custom compilation options we use (or others we don't use). -----Original Message----- From: Ben Pfaff [mailto:b...@nicira.com] Sent: Thursday, September 11, 2014 12:27 PM To: Eitan Eliahu Cc: Gurucharan Shetty; dev@openvswitch.org; Gurucharan Shetty Subject: Re: [ovs-dev] [PATCH 3/3] Avoid uninitialized variable warnings with OBJECT_OFFSETOF() in MSVC. On Thu, Sep 11, 2014 at 07:20:13PM +0000, Eitan Eliahu wrote: > > Here is the local warning suppression : > #define OBJECT_OFFSETOF(OBJECT, MEMBER) __pragma(pack(push, 1)) > __pragma(warning(disable:4700)) ((char *)&(OBJECT)->MEMBER - (char > *)(OBJECT)) __pragma(pack(pop)) > > > The right way to do it is as follows, but it doesn't work on OVS source base, > > struct my_node { > int first; > int extra_data; > }; > > #define OBJECT_OFFSETOF1(OBJECT, MEMBER) \ > ((LONG)(LONG_PTR)&((decltype(OBJECT))0)->MEMBER) > > int _tmain(int argc, _TCHAR* argv[]) > { > long l1 = (long)OBJECT_OFFSETOF1(node, extra_data); > printf("Number is %d\n", l1); > return 0; > } Do you know why it doesn't work? _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev