Skip to content

UB40⚓︎

Author: Kai Xu

Definition⚓︎

A pointer is converted to other than an integer or pointer type (6.5.4).

指针被转化为integer或指针以外的类型

Description⚓︎

Detailed instructions can be found in the standard (6.5.4.3), (6.5.4.4).

详细说明见标准(6.5.4.3)、(6.5.4.4)

Code⚓︎

UB40.c
#include "stdio.h"

int a;
int *p = &a;

int main() {
    printf("p = %p\n", p);
    printf("*p = %f\n", (float) p);
}

Configurations⚓︎

OS: Microsoft Windows 10 22H2

gcc -v: gcc version 8.1.0 x86_64-w64-mingw32

compile and run commands: gcc -o UB40.exe UB40.c && UB40.exe

OS: arm64-apple-darwin20.6.0

clang -v: Apple clang version 13.0.0 (clang-1300.0.29.30)

compile and run commands: clang -o UB40.out UB40.c && ./UB40.out

Behaviors⚓︎

error: pointer value used where a floating point value was expected

error: pointer cannot be cast to type 'float'