From 441361eda96ea2adf8cdffbb1af34020e595c867 Mon Sep 17 00:00:00 2001 From: axionbuster Date: Sat, 9 Mar 2024 22:37:57 -0800 Subject: [PATCH] Fix MSVC Warnings --- demo/env.h | 6 +++--- demo/main.cpp | 12 +++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/demo/env.h b/demo/env.h index cc3cc32..18b92c5 100644 --- a/demo/env.h +++ b/demo/env.h @@ -9,12 +9,12 @@ namespace env { std::optional get(char const *sv) { #ifdef _WIN32 - char *s; - size_t n; + char *s{}; + size_t n{}; // On Windows, _dupenv_s is the Microsoft-recommended way of reading an // environment variable. When the variable isn't found, the error (e) is 0 and // the count (n) is also 0 (also, the buffer [s] is set to NULL). - if (auto e = _dupenv_s(&s, &n, sv); e || !n) + if (auto e = _dupenv_s(&s, &n, sv); e || !s) return {}; std::string t{s, n}; // According to Microsoft, the buffer s must be freed using a call to `free`. diff --git a/demo/main.cpp b/demo/main.cpp index 13b96d5..df5fdc5 100644 --- a/demo/main.cpp +++ b/demo/main.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include @@ -15,9 +14,13 @@ #include "Table.h" #include "env.h" #include "user.h" +#include +#include using namespace phy; +namespace main_program { + /// Constants controlling the program. struct Constants { /// Inclusive upper limit of the number of particles. @@ -211,7 +214,7 @@ struct State { EndDrawing(); } - User make_user() { + User make_user() const { User u; if (constants.flags.galaxies) u.control.demo = false; @@ -222,10 +225,13 @@ struct State { return constants.flags.galaxies ? galaxies(constants) : figure8(); } } state; +} // namespace main_program -void do_loop() { state.loop(); } +void do_loop() { main_program::state.loop(); } static int do_main() { + using namespace main_program; + SetConfigFlags(FLAG_WINDOW_RESIZABLE); InitWindow(600, 600, "Grass Gravity Simulation");