From d3385953db708ea4f5cd74585d78e558c807621b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Fri, 12 Apr 2024 23:04:33 +0900 Subject: [PATCH] fix(compile): 'for' loop initial declarations are only allowed in C99 mode --- CMakeLists.txt | 6 ------ cmoe.c | 8 +++++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index df9427b..92910ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,12 +5,6 @@ SET(CMAKE_BUILD_TYPE "Release") include_directories("/usr/local/include") link_directories("/usr/local/lib") -if (NOT BUILD STREQUAL "docker") - #在编译选项中加入c99支持 - add_compile_options(-std=c99) - message(STATUS "optional:-std=c99") -endif () - add_executable(cmoe cmoe.c) add_executable(cmoeditor editor.c) diff --git a/cmoe.c b/cmoe.c index d56045d..00c30bd 100644 --- a/cmoe.c +++ b/cmoe.c @@ -83,7 +83,8 @@ static inline int add_user(char* name, uint32_t count, FILE* fp) { static inline uint32_t get_content_len(int isbig, uint16_t* len_type, char* cntstr) { uint32_t len = sizeof(svg_small) // small & big has the same len + sizeof(svg_tail) - 1; - for (int i = 0; cntstr[i]; i++) { + int i = 0; + for (; cntstr[i]; i++) { len += len_type[cntstr[i] - '0'] + (sizeof(img_slot_front) + sizeof(img_slot_rear) - 2); if (i > 0) len++; if (i > 2-isbig) len++; @@ -111,7 +112,8 @@ static void return_count(FILE* fp, char* name, char* theme) { char cntstrbuf[11]; sprintf(cntstrbuf, "%010u", d->count); char* cntstr = cntstrbuf; - for (int i = 0; i < 10; i++) if (cntstrbuf[i] != '0') { + int i = 0; + for (; i < 10; i++) if (cntstrbuf[i] != '0') { if (i > 2) cntstr = cntstrbuf+i-2; break; } @@ -143,7 +145,7 @@ static void return_count(FILE* fp, char* name, char* theme) { return; } printf(head, w*(10+cntstrbuf-cntstr)); - for (int i = 0; cntstr[i]; i++) { + for (i = 0; cntstr[i]; i++) { printf(img_slot_front, w * i, w, h); int n = cntstr[i] - '0'; fwrite(theme_type[n], len_type[n], 1, stdout);