Jul 15, 2023

[C++] unsigned char and std::byte under indeterminate byte read is not UB

 


https://en.cppreference.com/w/cpp/language/default_initialization
https://en.cppreference.com/w/cpp/types/byte

int f(bool b)
{
    int x;               // OK: the value of x is indeterminate
    int y = x;           // undefined behavior
    unsigned char c;     // OK: the value of c is indeterminate
    unsigned char d = c; // OK: the value of d is indeterminate
    int e = d;           // undefined behavior
    return b ? d : 0;    // undefined behavior if b is true
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.