Skip to content

Commit 45b29b9

Browse files
committed
Steal the CLITERAL idea from Raylib
1 parent 107dbcf commit 45b29b9

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

nob.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,17 @@ typedef struct {
339339
} Nob_Cmd_Opt;
340340

341341
NOBDEF bool nob_cmd_run_opt(Nob_Cmd *cmd, Nob_Cmd_Opt opt);
342+
343+
// NOTE: MSVC C++ compiler does not support compound literals (C99 feature)
344+
// Plain structures in C++ (without constructors) can be initialized with { }
345+
// This is called aggregate initialization (C++11 feature)
342346
#if defined(__cplusplus)
343-
#define nob_cmd_run(cmd, ...) nob_cmd_run_opt(cmd, { __VA_ARGS__ })
347+
#define CLITERAL(type) type
344348
#else
345-
#define nob_cmd_run(cmd, ...) nob_cmd_run_opt(cmd, (Nob_Cmd_Opt) { __VA_ARGS__ })
346-
#endif // _MSC_VER
349+
#define CLITERAL(type) (type)
350+
#endif
351+
352+
#define nob_cmd_run(cmd, ...) nob_cmd_run_opt(cmd, CLITERAL(Nob_Cmd_Opt){ __VA_ARGS__ })
347353

348354
// DEPRECATED:
349355
//

0 commit comments

Comments
 (0)