Add C++ compatibility guard
Just add micro checking code to microui.h. Since than these codes can be introduced into C++ projects more easily.
eh
microui can be compiled as C++ without errors, which then allows the use of type checking to the microui interface
Indeed so.
I build a C++ progrom with microui then I found I must carefully make the #include instructions surrounded by extern "C" block, or the compiler would report errors, because the symbols of C functions, types and global variables is different from C++'s.
It is worthwhile to add the "#ifdef __cplusplus ... #endif" guard to microui.h.
@chirsz-ever That's because you compiled microui as C, not C++. Just force it to compile as C++.
Visual Studio : change extension to .cpp, or specify /TP on microui.c, or right click the file and set force compile as C++ CMake : SET_SOURCE_FILES_PROPERTIES( microui.c PROPERTIES LANGUAGE CXX ) gcc : use g++ instead of gcc, or specify -x c++ microui.c clang : use clang++, or specify -x c++ microui.c
I know, but add the guard is (almost) always easier. If someone want use microui as a library (static or dynamic), the C symbols would be linked more easily (the user could pay no attention to the compiler version), and the library would be able to be exported to other languages.
I'm not sure what you mean by "exported to other languages", but if you're talking about mapping to say Lua or whatever, it's always easier in C than C++.
As for building microui as a library, it totally defies its purpose. It's a simple droppable file with minimalistic/core features only. It makes really no sense to build it as a library. I, for one, even merged the header and the implementation in one file, stb style.
OK, I think it jusk like the lua.h...
If someone want use extern "C", just do as the lua.hpp:
// microui.hpp
extern "C" {
#include "microui.h"
}