Skip to content

Commit

Permalink
Windows: Fixing Windows C++ compilation issues with unnamed structure
Browse files Browse the repository at this point in the history
MSVC does not allow to redefine unnamed structure in union.
Thus, this fix defines the struct outside of the anonymous union
in order to calculate the padded size.

Signed-off-by: Shireesh Kumar Singh <[email protected]>
Co-authored-by:Sairam Venugopal <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
shirsing0712 authored and blp committed Dec 19, 2017
1 parent 99b09c6 commit 5383723
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions include/openvswitch/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ OVS_NO_RETURN void ovs_assert_failure(const char *, const char *, const char *);
/* C++ doesn't allow a type declaration within "sizeof", but it does support
* scoping for member names, so we can just declare a second member, with a
* name and the same type, and then use its size. */
#define PADDED_MEMBERS(UNIT, MEMBERS) \
union { \
struct { MEMBERS }; \
struct { MEMBERS } named_member__; \
uint8_t PAD_ID[ROUND_UP(sizeof named_member__, UNIT)]; \
#define PADDED_MEMBERS(UNIT, MEMBERS) \
struct named_member__ { MEMBERS }; \
union { \
struct { MEMBERS }; \
uint8_t PAD_ID[ROUND_UP(sizeof(struct named_member__), UNIT)]; \
}
#endif

Expand Down Expand Up @@ -233,11 +233,11 @@ OVS_NO_RETURN void ovs_assert_failure(const char *, const char *, const char *);
}
#else
#define PADDED_MEMBERS_CACHELINE_MARKER(UNIT, CACHELINE, MEMBERS) \
struct struct_##CACHELINE { MEMBERS }; \
union { \
OVS_CACHE_LINE_MARKER CACHELINE; \
struct { MEMBERS }; \
struct { MEMBERS } named_member_##CACHELINE; \
uint8_t PAD_ID[ROUND_UP(sizeof named_member_##CACHELINE, UNIT)]; \
uint8_t PAD_ID[ROUND_UP(sizeof(struct struct_##CACHELINE), UNIT)]; \
}
#endif

Expand Down

0 comments on commit 5383723

Please sign in to comment.