Skip to content

UB48⚓︎

Author: Tianlin Xiao.

Definition⚓︎

An expression is shifted by a negative number or by an amount greater than or equal to the width of the promoted expression (6.5.7).

Description⚓︎

The integer promotions are performed on each of the operands. The type of the result is that of the promoted left operand. If the value of the right operand is negative or is greater than or equal to the width of the promoted left operand, the behavior is undefined.

一个表达式进行移动操作时,若移动的位数为负数或大于或等于提升表达式的宽度,则该行为未定义。

Code⚓︎

#include<stdio.h>

int main()
{
    int a=1;
    printf("%d",a<<32);
    return 0;
}

Configuration⚓︎

Configuration 1.⚓︎

MSVC version 1929

Configuration 2.⚓︎

gcc version 8.1.0 
Target: x86_64-w64-mingw32

Behaviors⚓︎

Configuration 1.⚓︎

- Compilation successful
- Output:1

Configuration 2.⚓︎

- Compilation successful
- Output:0