Is there a platform or situation where dereferencing (but not using) a null pointer to make a null reference will behave badly?

前端 未结 6 1658
春和景丽
春和景丽 2020-12-03 02:45

I\'m currently using a library that uses code like

T& being_a_bad_boy()
{
    return *reinterpret_cast(0);
}

to make a refere

6条回答
  •  感情败类
    2020-12-03 03:24

    I would expect that on most platforms, the compiler will convert all references into pointers. If that assumption is true, then this will be identical to just passing around a NULL pointer, which is fine as long as you never use it. The question, then is whether there are any compilers that handle references in some way other than just converting them to pointers. I don't know of any such compilers, but I suppose it's possible that they exist.

提交回复
热议问题