Is it safe to use bit_cast for any aliasing puroposes

Viewed 68

I use memcpy() to alias data in memory. AFAIK that's the only legal way to do aliasing in C++ (aliasing rules are different for C and C++ are different).

Can I use bit_cast to have the same more conveniently. So is this legal code:

double aliasDouble( char const *p )
{
    return std::bit_cast<double>( (char (&)[sizeof(double)])*p );
}
0 Answers
Related