[ovs-dev] [PATCH 3/3] Avoid uninitialized variable warnings with OBJECT_OFFSETOF() in MSVC.

Ben Pfaff blp at nicira.com
Thu Sep 11 19:27:04 UTC 2014


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?



More information about the dev mailing list