您是否嘗試過這個?:
enum {
val1 = (int)0xFFFFFFFFu,
val2 = (int)0xFFFFFFFEu,
val3 = (int)0xFFFFFFF0
};
編輯:我剛裝上的GCC Cygwin和嘗試了這一點。
測試enum.c是原始版本,測試枚舉int.c的一個用明確的轉換:
$ cc -std=c11 -pedantic-errors -c test-enum.c
test-enum.c:2:8: error: ISO C restricts enumerator values to range of 'int' [-Wpedantic]
val1 = 0xFFFFFFFFu,
^
test-enum.c:3:8: error: ISO C restricts enumerator values to range of 'int' [-Wpedantic]
val2 = 0xFFFFFFFEu,
^
test-enum.c:4:8: error: ISO C restricts enumerator values to range of 'int' [-Wpedantic]
val3 = 0xFFFFFFF0u
^
$ cc -std=c11 -pedantic-errors -c test-enum-int.c
(無投訴)
$ cc --version
cc (GCC) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.
arent'tÇ進行枚舉簽署值? –
這是抱怨,因爲你試圖使用一個無符號的文字爲一個有符號的整數。 –
不幸的是,刪除'u'後它仍然不起作用(同樣的錯誤) –