Add error if raylib.h is included in a C++98 program (#3093)
The color macros don't work properly in C++98, because they require aggregate initialzation, which is a C++11 feature. So, explicitly state how to fix this issue, instead of letting the compiler give a more vague error message like: main.cpp:8:23: error: expected '(' for function-style cast or type construction ClearBackground(BLACK); ^~~~~ /opt/homebrew/Cellar/raylib/4.5.0/include/raylib.h:179:35: note: expanded from macro 'BLACK' #define BLACK CLITERAL(Color){ 0, 0, 0, 255 } // Black NOTE: Don't use this check with MSVC because by default, it reports 199711L regardless of any C++ version passed on command line Only passing `/Zc:__cplusplus` will make MSVC set this correctly see: https://learn.microsoft.com/en-us/cpp/build/reference/zc-cplusplus
This commit is contained in:
parent
e497603678
commit
2dec56e7b7
1 changed files with 8 additions and 0 deletions
|
@ -133,12 +133,20 @@
|
||||||
|
|
||||||
// NOTE: MSVC C++ compiler does not support compound literals (C99 feature)
|
// NOTE: MSVC C++ compiler does not support compound literals (C99 feature)
|
||||||
// Plain structures in C++ (without constructors) can be initialized with { }
|
// Plain structures in C++ (without constructors) can be initialized with { }
|
||||||
|
// This is called aggregate initialization (C++11 feature)
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
#define CLITERAL(type) type
|
#define CLITERAL(type) type
|
||||||
#else
|
#else
|
||||||
#define CLITERAL(type) (type)
|
#define CLITERAL(type) (type)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Some compilers (mostly macos clang) default to C++98,
|
||||||
|
// where aggregate initialization can't be used
|
||||||
|
// So, give a more clear error stating how to fix this
|
||||||
|
#if !defined(_MSC_VER) && (defined(__cplusplus) && __cplusplus < 201103L)
|
||||||
|
#error "C++11 or later is required. Add -std=c++11"
|
||||||
|
#endif
|
||||||
|
|
||||||
// NOTE: We set some defines with some data types declared by raylib
|
// NOTE: We set some defines with some data types declared by raylib
|
||||||
// Other modules (raymath, rlgl) also require some of those types, so,
|
// Other modules (raymath, rlgl) also require some of those types, so,
|
||||||
// to be able to use those other modules as standalone (not depending on raylib)
|
// to be able to use those other modules as standalone (not depending on raylib)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue