summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmin Mesbah <mesbahamin@gmail.com>2017-11-10 19:05:40 -0800
committerAmin Mesbah <mesbahamin@gmail.com>2017-11-10 19:05:40 -0800
commit01aa330216076881c11618adf40dcf22c8ea019c (patch)
tree7f4e760546b8c53b5e3eead980ca46992d104fa5
parentbde61bd1485d04205ee0509df7fd0f5b871004e5 (diff)
downloadohsp-01aa330216076881c11618adf40dcf22c8ea019c.zip
ohsp-01aa330216076881c11618adf40dcf22c8ea019c.tar.gz
Use C99 style struct initialization
Safer (initializes struct members to 0) and easier to read. C99 Standard 6.7.8.21: If there are fewer initializers in a brace-enclosed list than there are elements or members of an aggregate, or fewer characters in a string literal used to initialize an array of known size than there are elements in the array, the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration.
-rw-r--r--src/entity.c8
-rw-r--r--src/platform_sdl.c29
2 files changed, 18 insertions, 19 deletions
diff --git a/src/entity.c b/src/entity.c
index dc99195..cb600bc 100644
--- a/src/entity.c
+++ b/src/entity.c
@@ -9,9 +9,11 @@ struct Vec2d vec2d_add(float angle1, float length1, float angle2, float length2)
float x = sinf(angle1) * length1 + sinf(angle2) * length2;
float y = cosf(angle1) * length1 + cosf(angle2) * length2;
- struct Vec2d new_vec;
- new_vec.angle = 0.5 * M_PI - atan2f(y, x);
- new_vec.length = hypotf(x, y);
+ struct Vec2d new_vec =
+ {
+ .angle = 0.5 * M_PI - atan2f(y, x),
+ .length = hypotf(x, y),
+ };
return new_vec;
}
diff --git a/src/platform_sdl.c b/src/platform_sdl.c
index 789b427..2c01a69 100644
--- a/src/platform_sdl.c
+++ b/src/platform_sdl.c
@@ -12,12 +12,12 @@
extern bool PAUSED;
-static struct SDLOffscreenBuffer global_back_buffer;
+static struct SDLOffscreenBuffer global_back_buffer = {0};
struct SDLWindowDimension sdl_get_window_dimension(SDL_Window *window)
{
- struct SDLWindowDimension result;
+ struct SDLWindowDimension result = {0};
SDL_GetWindowSize(window, &result.width, &result.height);
return(result);
}
@@ -238,15 +238,10 @@ int main(int argc, char *argv[])
uint64_t lag = 0;
uint64_t previous_ms = (SDL_GetPerformanceCounter() * SECOND) / SDL_GetPerformanceFrequency();
- struct GameState game_state;
+ struct GameState game_state = {0};
game_init(&game_state, dimension.width, dimension.height);
- struct GameControllerInput controller_input;
- controller_input.controller_index = 0;
- controller_input.left_stick_x = 0;
- controller_input.left_stick_y = 0;
- controller_input.right_stick_x = 0;
- controller_input.right_stick_y = 0;
+ struct GameControllerInput controller_input = {0};
while (running)
{
@@ -265,13 +260,15 @@ int main(int argc, char *argv[])
dimension = sdl_get_window_dimension(window);
- struct OffscreenBuffer buffer;
- // WARNING: these pointers are aliased until the end of the
- // loop
- buffer.memory = global_back_buffer.memory;
- buffer.width = global_back_buffer.width;
- buffer.height = global_back_buffer.height;
- buffer.pitch = global_back_buffer.pitch;
+ struct OffscreenBuffer buffer =
+ {
+ // WARNING: these pointers are aliased until the end of the
+ // loop
+ .memory = global_back_buffer.memory,
+ .width = global_back_buffer.width,
+ .height = global_back_buffer.height,
+ .pitch = global_back_buffer.pitch,
+ };
if (PAUSED)
{