diff --git a/src/lol/base/assert.h b/src/lol/base/assert.h index 8725cc60..3bc14bfa 100644 --- a/src/lol/base/assert.h +++ b/src/lol/base/assert.h @@ -29,21 +29,29 @@ static inline void Abort() #define LOL_EVAL(a) a #define LOL_1ST(a, ...) a -#define LOL_NUM2(a01, a02, a03, a04, a05, a06, a07, a08, a09, a10, \ - a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, \ - a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, \ - a31, a32, a33, a34, a35, a36, a37, a38, a39, a40, \ - a41, a42, a43, a44, a45, a46, a47, a48, a49, a50, \ - a51, a52, a53, a54, a55, a56, a57, a58, a59, a60, \ - a61, a62, a63, ...) a63 -#define LOL_NUM(...) \ - LOL_EVAL(LOL_NUM2(__VA_ARGS__, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \ - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \ - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \ - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \ - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \ - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \ - 2, 1, TOO_MANY_ARGUMENTS)) +#define LOL_GET_63RD(a01, a02, a03, a04, a05, a06, a07, a08, a09, a10, \ + a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, \ + a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, \ + a31, a32, a33, a34, a35, a36, a37, a38, a39, a40, \ + a41, a42, a43, a44, a45, a46, a47, a48, a49, a50, \ + a51, a52, a53, a54, a55, a56, a57, a58, a59, a60, \ + a61, a62, a63, ...) a63 +#define LOL_COUNT_TO_3(...) \ + LOL_EVAL(LOL_GET_63RD(__VA_ARGS__, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \ + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \ + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \ + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \ + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \ + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \ + 2, 1, TOO_FEW_ARGUMENTS)) +#define LOL_COUNT_TO_8(...) \ + LOL_EVAL(LOL_GET_63RD(__VA_ARGS__, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, \ + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, \ + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, \ + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, \ + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, \ + 8, 8, 8, 8, 8, 7, 6, 5, 4, 3, \ + 2, 1, TOO_FEW_ARGUMENTS)) /* Three levels of dispatch are needed because of Visual Studio's bizarre * handling of __VA_ARGS__ inside macro calls */ @@ -51,6 +59,35 @@ static inline void Abort() #define LOL_CAT2(a, b) LOL_CAT3(a,b) #define LOL_CAT(a, b) LOL_CAT2(a,b) +/* + * UNUSED(): declare one or several variables as unused + */ + +#define LOL_UNUSED_1(a01) \ + sizeof(a01) +#define LOL_UNUSED_2(a01, a02) \ + sizeof(a01) + LOL_UNUSED_1(a02) +#define LOL_UNUSED_3(a01, a02, a03) \ + sizeof(a01) + LOL_UNUSED_2(a02, a03) +#define LOL_UNUSED_4(a01, a02, a03, a04) \ + sizeof(a01) + LOL_UNUSED_3(a02, a03, a04) +#define LOL_UNUSED_5(a01, a02, a03, a04, a05) \ + sizeof(a01) + LOL_UNUSED_4(a02, a03, a04, a05) +#define LOL_UNUSED_6(a01, a02, a03, a04, a05, a06) \ + sizeof(a01) + LOL_UNUSED_5(a02, a03, a04, a05, a06) +#define LOL_UNUSED_7(a01, a02, a03, a04, a05, a06, a07) \ + sizeof(a01) + LOL_UNUSED_6(a02, a03, a04, a05, a06, a07) +#define LOL_UNUSED_8(a01, a02, a03, a04, a05, a06, a07, a08) \ + sizeof(a01) + LOL_UNUSED_7(a02, a03, a04, a05, a06, a07, a08) + +#define UNUSED(...) (void)sizeof((void)( \ + LOL_CALL(LOL_CAT(LOL_UNUSED_, LOL_CALL(LOL_COUNT_TO_8, (__VA_ARGS__))), \ + (__VA_ARGS__))), 0) \ + +/* + * ASSERT(): test and enforce conditions at runtime + */ + #define LOL_ERROR_1(t) \ Log::Error("assertion failure: " #t "\n") @@ -61,12 +98,13 @@ static inline void Abort() Log::Error("assertion failure: " s "\n", __VA_ARGS__) #if FINAL_RELEASE -# define ASSERT(...) (void)sizeof(LOL_CALL(LOL_1ST, (__VA_ARGS__))) +# define ASSERT(...) UNUSED(LOL_CALL(LOL_1ST, (__VA_ARGS__))) #else # define ASSERT(...) \ if (!(LOL_CALL(LOL_1ST, (__VA_ARGS__)))) \ { \ - LOL_CALL(LOL_CAT(LOL_ERROR_, LOL_CALL(LOL_NUM, (__VA_ARGS__))), \ + LOL_CALL(LOL_CAT(LOL_ERROR_, LOL_CALL(LOL_COUNT_TO_3, \ + (__VA_ARGS__))), \ (__VA_ARGS__)); \ Abort(); \ } diff --git a/src/platform/android/androidapp.cpp b/src/platform/android/androidapp.cpp index 0f94d9ff..dd4d3fc6 100644 --- a/src/platform/android/androidapp.cpp +++ b/src/platform/android/androidapp.cpp @@ -173,14 +173,11 @@ Java_org_zoy_LolEngine_LolRenderer_nativeRender(JNIEnv* env) void lol_android_main(void) {} void lol_android_main(int argc, char **argv) { - (void)argc; - (void)argv; + UNUSED(argc, argv); } void lol_android_main(int argc, char **argv, char **envp) { - (void)argc; - (void)argv; - (void)envp; + UNUSED(argc, argv, envp); } #endif /* __ANDROID__ */ diff --git a/test/benchsuite.cpp b/test/benchsuite.cpp index 09a28f61..755b9781 100644 --- a/test/benchsuite.cpp +++ b/test/benchsuite.cpp @@ -26,6 +26,8 @@ void bench_half(int mode); int main(int argc, char **argv) { + UNUSED(argc, argv); + Log::Info("-----------------------\n"); Log::Info(" High precision floats\n"); Log::Info("-----------------------\n"); diff --git a/test/math/pi.cpp b/test/math/pi.cpp index 8193d48a..771bd2a5 100644 --- a/test/math/pi.cpp +++ b/test/math/pi.cpp @@ -23,6 +23,8 @@ using lol::real; int main(int argc, char **argv) { + UNUSED(argc, argv); + printf("Pi: "); real::R_PI().print(); printf("e: "); real::R_E().print(); printf("ln(2): "); real::R_LN2().print(); diff --git a/test/math/poly.cpp b/test/math/poly.cpp index 4d833351..f6ac4c86 100644 --- a/test/math/poly.cpp +++ b/test/math/poly.cpp @@ -97,6 +97,8 @@ static float floatsin(float f) int main(int argc, char **argv) { + UNUSED(argc, argv); + typedef union { float f; uint32_t x; } flint; int error[5] = { 0 }; @@ -108,17 +110,6 @@ int main(int argc, char **argv) inspect(a4); inspect(a5); -//flint v = { 1.433971524239 }; -flint v = { 1.555388212204 }; -inspect(v.f); -printf("sinf: "); -flint w = { sinf(adjustf(v.f, 0)) }; -inspect(w.f); -printf("lols: "); -flint z = { lol_sin(adjustf(v.f, 0)) }; -inspect(z.f); - -printf("-- START --\n"); for (flint u = { (float)real::R_PI_2() }; u.f > 1e-30; u.x -= 1) { union { float f; uint32_t x; } s1 = { sinf(adjustf(u.f, 0)) }; @@ -129,9 +120,6 @@ printf("-- START --\n"); case 3: case 2: case 1: -inspect(u.f); -printf("sinf: "); -inspect(sinf(u.f)); if (lol::abs((double)s1.f - (double)s2.f) > 1e-10 * lol::abs(s1.f)) printf("%15.13g %08x: %15.13g %15.13g %08x %08x\n", u.f, u.x, s1.f, s2.f, s1.x, s2.x); case 0: diff --git a/test/math/remez.cpp b/test/math/remez.cpp index 48338020..19483ec1 100644 --- a/test/math/remez.cpp +++ b/test/math/remez.cpp @@ -26,6 +26,8 @@ real g(real const &x) { return exp(x); } int main(int argc, char **argv) { + UNUSED(argc, argv); + RemezSolver<4, real> solver; solver.Run(-1, 1, f, g, 40); return 0; diff --git a/test/sandbox/sample.cpp b/test/sandbox/sample.cpp index b9c7beae..d8fb6caa 100644 --- a/test/sandbox/sample.cpp +++ b/test/sandbox/sample.cpp @@ -14,18 +14,13 @@ #include "core.h" -class Moo -{ - Moo() {} - - virtual int SetState(int state) { return state; } -}; - using namespace std; using namespace lol; int main(int argc, char **argv) { + UNUSED(argc, argv); + /* Insert any test code here */ return EXIT_SUCCESS; } diff --git a/test/testsuite.cpp b/test/testsuite.cpp index 6cf49a7e..b4498055 100644 --- a/test/testsuite.cpp +++ b/test/testsuite.cpp @@ -21,6 +21,8 @@ int main(int argc, char **argv) { + UNUSED(argc, argv); + lol::TextTestRunner runner; bool success = runner.Run(); return success ? EXIT_SUCCESS : EXIT_FAILURE; diff --git a/test/xolotl/xolotl.cpp b/test/xolotl/xolotl.cpp index eed5738a..d6180cb7 100644 --- a/test/xolotl/xolotl.cpp +++ b/test/xolotl/xolotl.cpp @@ -56,6 +56,8 @@ private: int main(int argc, char **argv) { + System::Init(argc, argv); + Application app("Xolotl", ivec2(640, 480), 60.0f); /* Register some debug stuff */