[PATCH] erofs-utils: fix compilation error due to const static init

Li Yiyan lyy0627 at sjtu.edu.cn
Tue Jul 25 18:50:20 AEST 2023


gcc-7 and earlier versions fail to  infer the initial
value of a const global variable from another
const global variable. Therefore, compiling with gcc-7
and below will result in failure. In fact, for global
const variables, using macros is a better choice.

Signed-off-by: Li Yiyan <lyy0627 at sjtu.edu.cn>
---
 lib/kite_deflate.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/kite_deflate.c b/lib/kite_deflate.c
index f5bb2fd..91019e3 100644
--- a/lib/kite_deflate.c
+++ b/lib/kite_deflate.c
@@ -47,6 +47,11 @@ unsigned long erofs_memcmp2(const u8 *s1, const u8 *s2,
 #define kMatchMinLen		3
 #define kMatchMaxLen32		kNumLenSymbols32 + kMatchMinLen - 1
 
+#define kTableDirectLevels      16
+#define kBitLensRepNumber_3_6   kTableDirectLevels
+#define kBitLens0Number_3_10    (kBitLensRepNumber_3_6 + 1)
+#define kBitLens0Number_11_138  (kBitLens0Number_3_10 + 1)
+
 static u32 kstaticHuff_mainCodes[kFixedLenTableSize];
 static const u8 kstaticHuff_litLenLevels[kFixedLenTableSize] = {
 	[0   ... 143] = 8, [144 ... 255] = 9,
@@ -75,11 +80,6 @@ const u8 kCodeLengthAlphabetOrder[kLensTableSize] =
 
 const u8 kLevelExtraBits[3] = {2, 3, 7};
 
-const unsigned int kTableDirectLevels = 16;
-const unsigned int kBitLensRepNumber_3_6 = kTableDirectLevels;
-const unsigned int kBitLens0Number_3_10 = kBitLensRepNumber_3_6 + 1;
-const unsigned int kBitLens0Number_11_138 = kBitLens0Number_3_10 + 1;
-
 #define kStored			0
 #define kFixedHuffman		1
 #define kDynamicHuffman		2
-- 
2.34.1



More information about the Linux-erofs mailing list