From 2e1b0b6421251ae7bf420c91a836386f0a9bd041 Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Sat, 2 Mar 2024 20:17:22 -0500 Subject: [PATCH] Remove commented-out C-only macro features --- include/asm/symbol.hpp | 6 ++---- include/error.hpp | 8 ++++---- include/platform.hpp | 6 ------ src/asm/symbol.cpp | 2 +- src/error.cpp | 17 ++++++++--------- src/link/output.cpp | 1 - src/link/sdas_obj.cpp | 6 +++--- test/gfx/randtilegen.cpp | 14 +++++--------- 8 files changed, 23 insertions(+), 37 deletions(-) diff --git a/include/asm/symbol.hpp b/include/asm/symbol.hpp index 2278217b..da92d027 100644 --- a/include/asm/symbol.hpp +++ b/include/asm/symbol.hpp @@ -11,9 +11,7 @@ #include "asm/section.hpp" -#include "platform.hpp" // MIN_NB_ELMS - -#define MAXSYMLEN 255 +#define MAXSYMLEN 255 enum SymbolType { SYM_LABEL, @@ -72,7 +70,7 @@ void sym_SetExportAll(bool set); Symbol *sym_AddLocalLabel(char const *symName); Symbol *sym_AddLabel(char const *symName); Symbol *sym_AddAnonLabel(); -void sym_WriteAnonLabelName(char buf[MIN_NB_ELMS(MAXSYMLEN + 1)], uint32_t ofs, bool neg); +void sym_WriteAnonLabelName(char buf[/* MAXSYMLEN + 1 */], uint32_t ofs, bool neg); void sym_Export(char const *symName); Symbol *sym_AddEqu(char const *symName, int32_t value); Symbol *sym_RedefEqu(char const *symName, int32_t value); diff --git a/include/error.hpp b/include/error.hpp index c7b12e6f..efcd699a 100644 --- a/include/error.hpp +++ b/include/error.hpp @@ -8,11 +8,11 @@ extern "C" { -void warn(char const NONNULL(fmt), ...) format_(printf, 1, 2); -void warnx(char const NONNULL(fmt), ...) format_(printf, 1, 2); +void warn(char const *fmt ...) format_(printf, 1, 2); +void warnx(char const *fmt, ...) format_(printf, 1, 2); -[[noreturn]] void err(char const NONNULL(fmt), ...) format_(printf, 1, 2); -[[noreturn]] void errx(char const NONNULL(fmt), ...) format_(printf, 1, 2); +[[noreturn]] void err(char const *fmt, ...) format_(printf, 1, 2); +[[noreturn]] void errx(char const *fmt, ...) format_(printf, 1, 2); } diff --git a/include/platform.hpp b/include/platform.hpp index cf38cd97..8360df21 100644 --- a/include/platform.hpp +++ b/include/platform.hpp @@ -45,12 +45,6 @@ # include #endif -// C++ doesn't support `[static N]` for array arguments from C99 or C11 -#define MIN_NB_ELMS(N) // static (N) -#define ARR_QUALS(...) // __VA_ARGS__ -#define NONNULL(ptr) *ptr // ptr[static 1] -#define restrict - // MSVC uses a different name for O_RDWR, and needs an additional _O_BINARY flag #ifdef _MSC_VER # include diff --git a/src/asm/symbol.cpp b/src/asm/symbol.cpp index 909ddc9e..702bdc07 100644 --- a/src/asm/symbol.cpp +++ b/src/asm/symbol.cpp @@ -498,7 +498,7 @@ Symbol *sym_AddAnonLabel() } // Write an anonymous label's name to a buffer -void sym_WriteAnonLabelName(char buf[MIN_NB_ELMS(MAXSYMLEN + 1)], uint32_t ofs, bool neg) +void sym_WriteAnonLabelName(char buf[/* MAXSYMLEN + 1 */], uint32_t ofs, bool neg) { uint32_t id = 0; diff --git a/src/error.cpp b/src/error.cpp index 2165ee35..5d05b002 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -7,9 +7,8 @@ #include #include "error.hpp" -#include "platform.hpp" -static void vwarn(char const NONNULL(fmt), va_list ap) +static void vwarn(char const *fmt, va_list ap) { const char *error = strerror(errno); @@ -18,14 +17,14 @@ static void vwarn(char const NONNULL(fmt), va_list ap) fprintf(stderr, ": %s\n", error); } -static void vwarnx(char const NONNULL(fmt), va_list ap) +static void vwarnx(char const *fmt, va_list ap) { fprintf(stderr, "warning: "); vfprintf(stderr, fmt, ap); putc('\n', stderr); } -[[noreturn]] static void verr(char const NONNULL(fmt), va_list ap) +[[noreturn]] static void verr(char const *fmt, va_list ap) { const char *error = strerror(errno); @@ -36,7 +35,7 @@ static void vwarnx(char const NONNULL(fmt), va_list ap) exit(1); } -[[noreturn]] static void verrx(char const NONNULL(fmt), va_list ap) +[[noreturn]] static void verrx(char const *fmt, va_list ap) { fprintf(stderr, "error: "); vfprintf(stderr, fmt, ap); @@ -45,7 +44,7 @@ static void vwarnx(char const NONNULL(fmt), va_list ap) exit(1); } -void warn(char const NONNULL(fmt), ...) +void warn(char const *fmt, ...) { va_list ap; @@ -54,7 +53,7 @@ void warn(char const NONNULL(fmt), ...) va_end(ap); } -void warnx(char const NONNULL(fmt), ...) +void warnx(char const *fmt, ...) { va_list ap; @@ -63,7 +62,7 @@ void warnx(char const NONNULL(fmt), ...) va_end(ap); } -[[noreturn]] void err(char const NONNULL(fmt), ...) +[[noreturn]] void err(char const *fmt, ...) { va_list ap; @@ -71,7 +70,7 @@ void warnx(char const NONNULL(fmt), ...) verr(fmt, ap); } -[[noreturn]] void errx(char const NONNULL(fmt), ...) +[[noreturn]] void errx(char const *fmt, ...) { va_list ap; diff --git a/src/link/output.cpp b/src/link/output.cpp index 31256eb8..98bbeb5c 100644 --- a/src/link/output.cpp +++ b/src/link/output.cpp @@ -20,7 +20,6 @@ #include "error.hpp" #include "itertools.hpp" #include "linkdefs.hpp" -#include "platform.hpp" // For `MIN_NB_ELMS` and `AT` #define BANK_SIZE 0x4000 diff --git a/src/link/sdas_obj.cpp b/src/link/sdas_obj.cpp index 18a80d6b..b52ff1ee 100644 --- a/src/link/sdas_obj.cpp +++ b/src/link/sdas_obj.cpp @@ -72,7 +72,7 @@ retry: } } -static uint32_t readNumber(char const *restrict str, char const **endptr, enum NumberType base) { +static uint32_t readNumber(char const *str, char const **endptr, enum NumberType base) { uint32_t res = 0; for (;;) { @@ -88,7 +88,7 @@ static uint32_t readNumber(char const *restrict str, char const **endptr, enum N } } -static uint32_t parseNumber(FileStackNode const *where, uint32_t lineNo, char const *restrict str, enum NumberType base) { +static uint32_t parseNumber(FileStackNode const *where, uint32_t lineNo, char const *str, enum NumberType base) { if (str[0] == '\0') fatal(where, lineNo, "Expected number, got empty string"); @@ -100,7 +100,7 @@ static uint32_t parseNumber(FileStackNode const *where, uint32_t lineNo, char co return res; } -static uint8_t parseByte(FileStackNode const *where, uint32_t lineNo, char const *restrict str, enum NumberType base) { +static uint8_t parseByte(FileStackNode const *where, uint32_t lineNo, char const *str, enum NumberType base) { uint32_t num = parseNumber(where, lineNo, str, base); if (num > UINT8_MAX) diff --git a/test/gfx/randtilegen.cpp b/test/gfx/randtilegen.cpp index 8bb79077..a4c8e7a4 100644 --- a/test/gfx/randtilegen.cpp +++ b/test/gfx/randtilegen.cpp @@ -19,8 +19,6 @@ #include #include -#include "platform.hpp" - struct Attributes { unsigned char palette; unsigned char nbColors; @@ -48,7 +46,7 @@ static unsigned long long getRandomBits(unsigned count) { return result; } -static void generate_tile_attributes(Attributes * restrict attributes) { +static void generate_tile_attributes(Attributes *attributes) { /* * Images have ten colors, grouped into two groups of 5 colors. The palette index indicates two * things: which one of those groups will be used, and which colors out of those 5 will be used @@ -77,8 +75,7 @@ static void generate_tile_attributes(Attributes * restrict attributes) { attributes->nbColors = popcount[pal]; } -static void generate_tile_data(unsigned char tiledata[ARR_QUALS(restrict) MIN_NB_ELMS(8)][8], - unsigned colorcount) { +static void generate_tile_data(unsigned char tiledata[/* 8 */][8], unsigned colorcount) { switch (colorcount) { case 2: // 1bpp for (uint8_t y = 0; y < 8; y++) { @@ -109,8 +106,7 @@ static void generate_tile_data(unsigned char tiledata[ARR_QUALS(restrict) MIN_NB // Can't mark as `const`, as the array type is otherwise not compatible (augh) static void - copy_tile_data(unsigned char destination[ARR_QUALS(restrict) MIN_NB_ELMS(8)][8], - unsigned char /* const */ source[ARR_QUALS(restrict) MIN_NB_ELMS(8)][8]) { + copy_tile_data(unsigned char destination[/* 8 */][8], unsigned char /* const */ source[/* 8 */][8]) { // Apply a random rotation to the copy // coord ^ 7 = inverted coordinate; coord ^ 0 = regular coordinate unsigned xmask = getRandomBits(1) * 7; @@ -122,7 +118,7 @@ static void } } -static void generate_palettes(uint16_t palettes[ARR_QUALS(restrict) MIN_NB_ELMS(60)][4]) { +static void generate_palettes(uint16_t palettes[/* 60 */][4]) { uint16_t colors[10]; // Generate 10 random colors (two groups of 5 colors) for (unsigned p = 0; p < 10; p++) { @@ -153,7 +149,7 @@ static uint8_t _5to8(uint8_t five) { } // Can't mark as `const`, as the array type is otherwise not compatible (augh) -static void write_image(char const *filename, uint16_t /* const */ palettes[MIN_NB_ELMS(60)][4], +static void write_image(char const *filename, uint16_t /* const */ palettes[/* 60 */][4], unsigned char /* const */ (*tileData)[8][8], Attributes const *attributes, uint8_t width, uint8_t height) { uint8_t const nbTiles = width * height;