[英]What is the result type of the bit shift operator?
考慮以下清單: 它與 GCC 和 Clang 編譯得很好。我對operator<<(uint8_t, uint32_t)很困惑。 為什么結果被簽名? ...
[英]What is the result type of the bit shift operator?
考慮以下清單: 它與 GCC 和 Clang 編譯得很好。我對operator<<(uint8_t, uint32_t)很困惑。 為什么結果被簽名? ...
[英]How can I identify an integer promotion and a demotion in C?
我正在學習 C 和 integer 提升和降級這個詞對我來說是新的。 我在 C Standard (C17) 中讀到了關於 C 類型轉換和 integer 提升的信息,但我不知道如何識別 integer 提升,我對降級一無所知。 例如,如果我有這些代碼行: 哪里有integer促銷? 因為據我所知 ...
[英]Fixed point arithmetic long long int representation issue in C
我正在努力實現在其 integer 部分中設置值 1 的有符號 long long int 變量。 查看帶有有符號 long int 變量的 16.16 實現,它的工作原理如下: 這導致以下表示: 0001.0000 不幸的是,我無法讓它在 32.32 表示中工作: 我收到以下 gcc 警告: wa ...
[英]What is the result type of operation between integer literals?
int main(){ char a = 5 + (16711935 * 1200); return 0; } 根據integer 文字的類型和 C中的轉換規則, 16711935是 int 類型, 1200被提升為 int。 我的問題是這個乘法的中間結果在它被添加到 5 然后轉換為 char ...
[英]How does type conversion and integer promotion work for stdint.h?
在 C 中,我了解標准類型的類型轉換、integer 提升、轉換等,但是 stdint.h 類型如何影響這一點? 對於類型排名,規則 state: 任何兩個帶符號的 integer 類型都不應具有相同的等級,即使它們具有相同的表示形式。 任何無符號 integer 類型的等級應等於相應有符號 in ...
[英]what is the output of conditional operator with unary operator
我有以下代碼,我不清楚其中的行為。 有人可以幫助條件運算符如何評估以下代碼和 output ans 作為 1 #包括 Soemone 能否請幫助如何評估代碼“delayMessages += Delay?1:-1;” ...
[英]Why the sequence from the bitwise operator(~) would be this? Is that broken?
/結果應該是 155,不是嗎? / ...
[英](Where) does the C standard define the result of adding/subtracting two booleans?
C11 標准將_Bool類型(6.2.5.2)定義為標准無符號 integer 類型(6.2.5.6),當我閱讀標准時, _Bool也是一種算術類型(6.2.5.18 通過 6.2.5.7 和 6.2.5.17) . 此外,指定對於+和- “兩個操作數都應具有算術類型,或者一個操作數應是指向完整 ...
[英]avoiding array index promotion in hopes of better performance
我有一個巨大的整數數組,這些整數不大於0xFFFF 。 因此,我想節省一些空間並將它們存儲為unsigned short 。 后來我會使用這個數組如下 當我只使用 2 個字節來存儲我的整數時,它們在用作數組索引時被提升為 4 個或 8 個字節(取決於架構)。 速度對我來說非常重要,因此我是否應該將整 ...
[英]C language printf function and output problem
我需要幫助解決這個問題,所以如果有人遇到類似的問題,它會對我有很大幫助。 為什么輸出是101? ...
[英]Printf in unsigned short int and unsigned int using %d
為什么在使用 %d 時在第二個 printf 中我沒有得到 -1? ...
[英]Why does function return bool when it is defined as an int?
為什么int hum2()函數返回布爾類型? 函數不應該返回我定義的類型。 就像 Float 函數返回浮點值一樣,Double 函數返回一個雙精度值。 ...
[英]Conversion Warning with Bitwise Or and Casted Operands
代碼片段 1(如下所示)產生以下 -Wconversion 警告: 代碼片段 2 和 3 不會產生 -Wconversion 警告。 代碼片段 1: 代碼片段 2: 代碼片段 3: 為什么第一個代碼片段會產生警告,而其他代碼片段不會? 導致警告的具體原因是什么? 我覺得這很令人困 ...
[英]Why does printf's hh and h length modifiers exist?
在可變參數函數中,會發生默認參數提升。 6.5.2.2.6 如果表示被調用函數的表達式的類型不包含原型,則對每個參數執行整數提升,而float類型的參數提升為double 。 這些稱為默認參數提升。 [...] 6.5.2.2.7 [...] 函數原型聲明符中的省略號會導致參數類 ...
[英]Using smallest necessary C type vs just using int
給定一個 C 函數(隨機示例): 使用unsigned char是通過告訴編譯器傳遞的值的限制來幫助編譯器,還是通過阻止編譯器使用本機int (或unsigned int )大小來阻礙編譯器? 我知道歷史上使用short並不理想,因為 16 位操作不是原生的。 我不知道這是否適用於這里(或一般 ...
[英]Why do a bitwise-and of a character with 0xff?
我正在閱讀一些實現簡單解析器的代碼。 名為scan的 function 將一行分解為標記。 scan有一個 static 變量bp ,它分配了要標記的行。 在賦值之后,空白被跳過。 見下文。 我不明白的是為什么代碼會按位和bp指向的字符0xff ,即* bp & 0xff的目的是什么? ...
[英]Integer arithmetic overflow prevention in C
我認為以下代碼可能會導致溢出,因為a * 65535大於unsigned short int可以容納的值,但結果似乎是正確的。 C 中是否有一些內置機制將中間算術結果存儲在更大的數據類型中? 或者它是一個意外? ...
[英]int to char cast, strange behavior
考慮以下:unsigned int i1 = 0xFFFFFFFF; unsigned char c1 = i1; char c2 = i1; printf("%x\n", i1); // 0xFFFFFFFF as expected printf("%x\n", ...
[英]Promotions and conversions of variables in printf()
在這種情況下, printf 中的參數-a通過一元減號運算符的printf提升提升為int ,隨后通過默認參數提升提升,最后通過格式說明符轉換為unsigned char 。 所以-a => -(int)a (by ~ ) => function call => (unsigne ...