From 9c0678a2911e132cdd2607f30cc1d22eb167a987 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Thu, 12 Aug 2021 12:20:07 +0200 Subject: [PATCH] Avoid duplicate const specifier compiler warnings The original code is perfectly valid standard C. However, some compilers (especially GCC) complain about duplicate const specifiers anyway. At this point we cave in as there doesn't seem to be any efforts to fix this problem by the corresponding compiler vendors. uGFX v3 will no longer suffer from this problem as the driver interface works differently in this area. --- drivers/multiple/Win32/gdisp_lld_Win32.c | 8 ++++++-- src/gdisp/gdisp.c | 4 ++-- src/gdisp/gdisp_driver.h | 6 +++++- src/gdriver/gdriver.h | 10 +++++++++- src/gfile/gfile.c | 5 ++++- src/gfile/gfile_fs_rom.c | 7 ++++++- src/ginput/ginput_mouse.c | 6 +++++- 7 files changed, 37 insertions(+), 9 deletions(-) diff --git a/drivers/multiple/Win32/gdisp_lld_Win32.c b/drivers/multiple/Win32/gdisp_lld_Win32.c index 1ec52a37..5b1390e7 100644 --- a/drivers/multiple/Win32/gdisp_lld_Win32.c +++ b/drivers/multiple/Win32/gdisp_lld_Win32.c @@ -99,7 +99,11 @@ static gBool Win32MouseInit(GMouse *m, unsigned driverinstance); static gBool Win32MouseRead(GMouse *m, GMouseReading *prd); - const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ + /** + * This should be: const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ + * However, some major compilers complain about the duplicate const specifier even though this is perfectly valid standard C. + */ + const GMouseVMT GMOUSE_DRIVER_VMT[1] = {{ { GDRIVER_TYPE_MOUSE, GMOUSE_VFLG_NOPOLL|GMOUSE_VFLG_DYNAMICONLY, @@ -885,7 +889,7 @@ LLDSPEC gBool gdisp_lld_init(GDisplay *g) { // Create the associated mouse #if GFX_USE_GINPUT && GINPUT_NEED_MOUSE priv->mouseenabled = hWndParent ? gFalse : gTrue; - priv->mouse = (GMouse *)gdriverRegister((const GDriverVMT const *)GMOUSE_DRIVER_VMT, g); + priv->mouse = (GMouse *)gdriverRegister((const GDriverVMT*)GMOUSE_DRIVER_VMT, g); #endif sprintf(buf, APP_NAME " - %u", g->systemdisplay+1); diff --git a/src/gdisp/gdisp.c b/src/gdisp/gdisp.c index 7b5438d7..c309dcbd 100644 --- a/src/gdisp/gdisp.c +++ b/src/gdisp/gdisp.c @@ -574,7 +574,7 @@ void _gdispInit(void) #elif GDISP_TOTAL_DISPLAYS > 1 { unsigned i; - extern const GDISPVMT const GDISPVMT_OnlyOne[1]; + extern const GDISPVMT GDISPVMT_OnlyOne[1]; if (!(GDISPVMT_OnlyOne->d.flags & GDISP_VFLG_DYNAMICONLY)) { for(i = 0; i < GDISP_TOTAL_DISPLAYS; i++) @@ -583,7 +583,7 @@ void _gdispInit(void) } #else { - extern const GDISPVMT const GDISPVMT_OnlyOne[1]; + extern const GDISPVMT GDISPVMT_OnlyOne[1]; if (!(GDISPVMT_OnlyOne->d.flags & GDISP_VFLG_DYNAMICONLY)) gdriverRegister(&GDISPVMT_OnlyOne->d, 0); diff --git a/src/gdisp/gdisp_driver.h b/src/gdisp/gdisp_driver.h index 936e2657..327e0b0a 100644 --- a/src/gdisp/gdisp_driver.h +++ b/src/gdisp/gdisp_driver.h @@ -732,7 +732,11 @@ typedef struct GDISPVMT { #endif // Build the VMT - const GDISPVMT const GDISP_DRIVER_VMT[1] = {{ + /* + * This should read: const GDISPVMT const GDISP_DRIVER_VMT[1] = {{ + * However, some major C compilers complain about duplicate const specifiers although this is perfectly valid standard C. + */ + const GDISPVMT GDISP_DRIVER_VMT[1] = {{ { GDRIVER_TYPE_DISPLAY, 0, sizeof(GDisplay), _gdispInitDriver, _gdispPostInitDriver, _gdispDeInitDriver }, gdisp_lld_init, #if GDISP_HARDWARE_DEINIT diff --git a/src/gdriver/gdriver.h b/src/gdriver/gdriver.h index 2b3ef7da..6a1f2061 100644 --- a/src/gdriver/gdriver.h +++ b/src/gdriver/gdriver.h @@ -86,8 +86,16 @@ typedef struct GDriverVMT { * const GDriverVMT const * mylist = { DRIVER_LIST }; * * + * @note This could be one single typedef. However, some major compilers complain about duplicate const specifiers even though this is perfectly + * valid standard C. As this problem has become worse over time we opt for splitting this into two separate typedefs to prevent these + * compilers from throwing warnings. + * The single typedef would look like this: + * + * typedef const struct GDriverVMT const GDriverVMTList[1]; + * */ -typedef const struct GDriverVMT const GDriverVMTList[1]; +typedef const struct GDriverVMT ConstGDriverVMT; +typedef ConstGDriverVMT const GDriverVMTList[1]; /*===========================================================================*/ /* External declarations. */ diff --git a/src/gfile/gfile.c b/src/gfile/gfile.c index 720ab815..4f535c39 100644 --- a/src/gfile/gfile.c +++ b/src/gfile/gfile.c @@ -36,8 +36,11 @@ /** * The order of the file-systems below determines the order * that they are searched to find a file. + * + * This should read: static const GFILEVMT const * FsArray[] = { + * However, some major C compilers complain about duplicate const specifiers although this is perfectly valid standard C. */ -static const GFILEVMT const * FsArray[] = { +static const GFILEVMT* FsArray[] = { #if GFILE_NEED_USERFS &FsUSERVMT, #endif diff --git a/src/gfile/gfile_fs_rom.c b/src/gfile/gfile_fs_rom.c index 56181086..57b27530 100644 --- a/src/gfile/gfile_fs_rom.c +++ b/src/gfile/gfile_fs_rom.c @@ -34,7 +34,12 @@ typedef struct ROMFS_DIRENTRY { #define ROMFS_DIRENTRY_HEAD 0 #include "romfs_files.h" -static const ROMFS_DIRENTRY const *FsROMHead = ROMFS_DIRENTRY_HEAD; + +/* + * This should be: static const ROMFS_DIRENTRY const *FsROMHead = ROMFS_DIRENTRY_HEAD; + * However, some major compilers complain about the duplicate const specifier even though this is perfectly valid standard C. + */ +static const ROMFS_DIRENTRY *FsROMHead = ROMFS_DIRENTRY_HEAD; typedef struct ROMFileList { gfileList fl; diff --git a/src/ginput/ginput_mouse.c b/src/ginput/ginput_mouse.c index 6d08e1f3..b3ef3d81 100644 --- a/src/ginput/ginput_mouse.c +++ b/src/ginput/ginput_mouse.c @@ -663,7 +663,11 @@ void _gmouseInit(void) { // One and only one mouse #else { - extern const GMouseVMT const GMOUSEVMT_OnlyOne[1]; + /* + * This should be: extern const GMouseVMT const GMOUSEVMT_OnlyOne[1]; + * However, some major compilers complain about the duplicate const specifier even though this is perfectly valid standard C. + */ + extern const GMouseVMT GMOUSEVMT_OnlyOne[1]; if (!(GMOUSEVMT_OnlyOne->d.flags & GMOUSE_VFLG_DYNAMICONLY)) gdriverRegister(&GMOUSEVMT_OnlyOne->d, GDISP);