ICode9

精准搜索请尝试: 精确搜索
  • c-将结构转换为数组2019-10-12 11:10:12

    这个问题已经在这里有了答案:            >            Does accessing the first field of a struct via a C cast violate strict aliasing?                                    1个 >            Rein

  • c-std :: aligned_storage的static_cast和reinterpret_cast2019-10-10 14:13:04

    有人可以解释一下http://en.cppreference.com/w/cpp/types/aligned_storage中的转换代码吗? 可以下面的代码 return *static_cast<const T*>(static_cast<const void*>(&data[pos])); 被取代 return *reinterpret_cast<const T*>(&data[pos]); ? 为什么在这里使用两个铸造? 非常

  • c – 为什么我不能reintpret_cast uint到int?2019-10-05 14:14:43

    这就是我想要做的事情: const int64_t randomIntNumber = reinterpret_cast< int64_t> (randomUintNumber); randomUintNumber的类型为uint64_t. 错误是(MSVC 2010): error C2440: ‘reinterpret_cast’ : cannot convert from ‘const uint64_t’ to ‘int64_t’ 1> C

  • c – `reinterpret_cast`是`T *`到’T(*)[N]`是不确定的行为?2019-10-04 08:14:59

    请考虑以下情形: std::array<int, 8> a; auto p = reinterpret_cast<int(*)[8]>(a.data()); (*p)[0] = 42; 这是未定义的行为吗?我觉得是这样的. > a.data()返回一个int *,它与int(*)[8]不同 > cppreference上的type aliasing rules似乎表明reinterpret_cast无效>作为程序员,我知道

  • 我应该在C风格的演员表中使用C reinterpret_cast吗?2019-09-27 22:06:15

    我有以下模板函数用于将任何标准类型的数据转储到二进制输出流中. template<typename T> static void dump ( const T& v, ostream& o ) { o.write ( reinterpret_cast<const char*>(&v), sizeof(T)); } 我也可以使用C风格(const char *)代替reinterpret_cast.有没有特别的理

  • c – placement new的返回值与其操作数的转换值之间是否存在(语义)差异?2019-09-18 13:05:09

    放置new的返回值与其操作数的转换值之间是否存在(语义)差异? struct Foo { ... }; char buffer[...]; Foo *a = new(buffer) Foo; Foo *b = reinterpret_cast<Foo *>(buffer); a和b在某种程度上有所不同吗? 编辑:根据DaBler的评论,这个问题告诉我们,如果使用const / reference成员

  • c – 使用static_cast(或reinterpret_cast)进行无效向下转换的安全性,无需添加成员即可继承2019-08-31 05:08:12

    我想知道标准对以下代码的安全性的说法: class A { int v; }; class B: public A { }; // no added data member A a; B& b = static_cast<B&>(a); 显然,a的运行时类型是A,而不是B,因此强制转换实际上并不是类型安全的.但是,由于没有添加任何成员而且没有任何内容是虚拟的,IMO的

  • c – reinterpret_cast到函数指针2019-08-30 16:07:08

    我用reinterpret_cast< T>进行了实验的代码. #include <iostream> #include <cstdlib> using std::cout; using std::endl; int foo() { cout << "foo" << endl; return 0; } void (*bar)(); int main() { bar = reinterpret_

  • 转换为不同的基类会产生不同的结果. C2019-08-28 05:05:39

    也许我的问题没有完美形成,但我的代码将使一切都清楚. #include <iostream> using namespace std; struct A{int n;}; struct B{int n;}; struct C : A, B{}; int main() { C c; C* pc = &c; std::cout<<"TEST1"<<std::endl; cout << stati

  • c – std :: complex是否以交错的方式存储?2019-08-27 03:16:11

    也就是说,在磁盘上,如果我有一个std :: complex数组,它是存储RIRIRIRI还是RRRRIIII还是别的? 我真正的问题是 – 如果我有一个我定义的结构包含两个数字,我可以重新解释一下我的结构数组,以使用期望std :: complex数组的函数吗? memcpy怎么样?如果我的两个结构都是浮点数,那么如果它们

  • C:reinterpret_cast是这些场景中的最佳选择吗?2019-08-23 10:08:40

    这已经困扰了我很长时间:如何将指针从任何东西转换为char *以将二进制转储到磁盘. 在C中,你甚至没有考虑过它. double d = 3.14; char *cp = (char *)&d; // do what u would do to dump to disk 然而,在C中,每个人都说C-cast是不受欢迎的,我一直这样做: double d = 3.14; auto c

  • c – 从父母到孩子的什么类型的演员?2019-07-24 23:06:37

    这个问题是关于应该使用哪个C++ style cast进行此转换.我知道C风格的演员可以达到这个目的. 对于以下类结构: class Foo {}; class Bar : public Foo {}; 说我得到了:Foo * ptr;我想把它投到一个Bar *我应该使用哪种类型的演员?好像我必须使用dynamic_cast: Used for conversion o

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有