我想知道以下是否是未定义行为
// Case 1:
int *p = 0;
int const *q = *const_cast<int const* const*>(&p);
// Case 2: (I think this is the same)
int *p = 0;
int const *const *pp = &p;
int const *q = *pp;
如果将int*
作为int const*
读取,这是否属于未定义行为?我认为这是未定义行为,但我之前认为只是添加一般的const
是安全的,所以我不确定。
double*
给一个接受double const*
的函数会导致未定义行为吗?如果这是真的,我会感到惊讶。 - ildjarndouble **
传递给一个接受double const**
的函数是否会导致 UB(当该函数使用它时),但你提供的示例并不是这种 UB 的结果。如果这确实是 UB 的话,我的意思是。 - Steve Jessop