From 02484902ee864998b45e6fab8106b576bf3abac3 Mon Sep 17 00:00:00 2001 From: a dinosaur Date: Tue, 12 Mar 2024 20:12:26 +1100 Subject: [PATCH] c99 conversion --- CMakeLists.txt | 6 +++--- Lesson10.cpp => Lesson10.c | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) rename Lesson10.cpp => Lesson10.c (98%) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe311d9..6ee6460 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,12 @@ cmake_minimum_required(VERSION "3.5" FATAL_ERROR) -project(Lesson10 LANGUAGES CXX) +project(Lesson10 LANGUAGES C) find_package(SDL3 REQUIRED CONFIG) find_package(OpenGL REQUIRED) -add_executable(Lesson10 Lesson10.cpp) +add_executable(Lesson10 Lesson10.c) set_target_properties(Lesson10 PROPERTIES - CXX_STANDARD 98 + C_STANDARD 99 WIN32_EXECUTABLE ON) target_link_libraries(Lesson10 SDL3::SDL3 OpenGL::GL) target_compile_options(Lesson10 PRIVATE $<$:-Wall -Wextra -pedantic>) diff --git a/Lesson10.cpp b/Lesson10.c similarity index 98% rename from Lesson10.cpp rename to Lesson10.c index 27aaf65..22925ff 100644 --- a/Lesson10.cpp +++ b/Lesson10.c @@ -9,6 +9,7 @@ #include // Math Library Header File #include // Header File For Standard Input/Output #include +#include #include #include #include // Header File For The OpenGL32 Library @@ -90,7 +91,7 @@ void SetupWorld() readstr(filein, oneline); sscanf(oneline, "NUMPOLLIES %d\n", &numtriangles); - sector1.triangle = new TRIANGLE[numtriangles]; + sector1.triangle = malloc(sizeof(TRIANGLE) * numtriangles); sector1.numtriangles = numtriangles; for (int loop = 0; loop < numtriangles; loop++) { @@ -118,11 +119,11 @@ bool FlipSurface(SDL_Surface *surface) const int pitch = surface->pitch; const int numrows = surface->h; - unsigned char *pixels = (unsigned char*)surface->pixels; - unsigned char *tmprow = new unsigned char[pitch]; + unsigned char *pixels = (unsigned char *)surface->pixels; + unsigned char *tmprow = malloc(sizeof(unsigned char) * pitch); unsigned char *row1 = pixels; - unsigned char *row2 = pixels + (numrows- 1) * pitch; + unsigned char *row2 = pixels + (numrows - 1) * pitch; for (int i = 0; i < numrows / 2; ++i) { // Swap rows @@ -134,7 +135,7 @@ bool FlipSurface(SDL_Surface *surface) row2 -= pitch; } - delete[] tmprow; + free(tmprow); SDL_UnlockSurface(surface); return true; }