Skip to content

Commit 44d5625

Browse files
committed
Fix MSVC compile with likely()
I could have sworn I tested this before I commited, but apparently not!
1 parent 15bcd5e commit 44d5625

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/steamnetworkingsockets/steamnetworkingsockets_internal.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,26 @@ struct iovec
200200

201201
// likely() and unlikely(). Branch hints
202202
// This is an idiom from the linux kernel
203-
#if defined(__GNUC__) || (defined(__has_builtin) && __has_builtin(__builtin_expect))
203+
#ifdef __GNUC__
204204
#ifndef likely
205205
#define likely(x) __builtin_expect (!!(x), 1)
206206
#endif
207207
#ifndef unlikely
208208
#define unlikely(x) __builtin_expect (!!(x), 0)
209209
#endif
210210
#else
211+
// Nested check avoids MSVC preprocessor parse error (C1012) when
212+
// __has_builtin(...) appears in a single #if expression alongside ||.
213+
#ifdef __has_builtin
214+
#if __has_builtin(__builtin_expect)
215+
#ifndef likely
216+
#define likely(x) __builtin_expect (!!(x), 1)
217+
#endif
218+
#ifndef unlikely
219+
#define unlikely(x) __builtin_expect (!!(x), 0)
220+
#endif
221+
#endif
222+
#endif
211223
#ifndef likely
212224
#define likely(x) (x)
213225
#endif

0 commit comments

Comments
 (0)