Skip to content

Char reinterpret is (kind of) broken #29181

@StefanKarpinski

Description

@StefanKarpinski
julia> reinterpret(UInt32, reinterpret(Char, 0x00ff0000))
0x00000000

julia> u2c(u::UInt32) = reinterpret(Char, u)
u2c (generic function with 1 method)

julia> c2u(c::Char) = reinterpret(UInt32, c)
c2u (generic function with 1 method)

julia> u2c(0x00ff0000)
'\0': ASCII/Unicode U+0000 (category Cc: Other, control)

julia> c2u(u2c(0x00ff0000))
0x00000000

julia> u2u(u) = c2u(u2c(u))
u2u (generic function with 1 method)

julia> u2u(0x00ff0000)
0x00ff0000

julia> c2u(u2c(0x00ff0000))
0x00000000

The fortunate thing is that it doesn't seem to be broken in a way that affects any Char values that can be produced naturally—you can only produce the values for which this is broken through reinterpret of UInt32 values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions