strict-aliasing

    2热度

    1回答

    我有以下结构: typedef struct{ int data[LENGTH]; }Data; ,并使用它,像这样: Data* dt=CALLOC(...) int foo(Data* restrict d){ for(...) d[i]->data[j]; //do stuff with data[] } 我的问题是:是否从d去除严格

    2热度

    2回答

    我在一些遗留的源代码的行: #define MAXMSG 1024 ... char m_recvBuf[MAXMSG]; unsigned int msgLength = ntohl(*((unsigned int *)m_recvBuf)); 这产生以下警告: x.cpp: In member function ‘bool xx::cccc(std::string&)’: x.cp

    8热度

    3回答

    我的程序符合严格的别名规则,除了一个地方:一个包含散列函数(如MurmurHash3,SpookyHash等)的编译单元。在x86和x86_64上,这些散列函数接受const char *,将它们转换为uint32,数据以4字节为单位。这使得它们比逐字节地处理数据要快得多,但我相信这打破了严格的别名规则。现在,我用-fno-strict-aliasing编译这个编译单元,而我用-fstrict-a

    4热度

    1回答

    下面的代码单产G ++警告: #include <iostream> #include <cstdint> template <typename T, typename P, typename Q> Q T::*pointer_to(P T::*p, Q P::*q) { typedef Q T::* output_ptr; // warning: dereferencing

    1热度

    3回答

    struct test { char member1; char member2; }; int main(void) { struct test structure[] = {'h', 'i'}; static void* p = &structure; printf("%i", *((int*)p)); return 0

    5热度

    1回答

    我使用std::aligned_storage作为变体模板的后备存储。问题是,一旦我在gcc上启用了-O2,我开始收到警告'dereferencing type-punned pointer will break strict aliasing`。 真正的模板要复杂得多(类型在运行时检查),但一个小例子,生成警告: struct foo { std::aligned_storage<1

    0热度

    1回答

    我写了一个类来存储一个函数指针或一个成员函数指针(不是每次都是)。当我存储成员函数指针时,我也存储一个对象指针(接收者)。 问题是:我不提前知道对象的类型和函数签名,所以我使用模板类型名。对于我使用可变参数模板的参数。 我有一个类似的代码: template <typename... Args> class A { public: template <typename Object

    18热度

    4回答

    我试图检查我的一些代码是否存在严格的别名违规行为,但它似乎在尝试理解严格别名 规则时错过了某些内容。 想象以下代码: #include <stdio.h> int main(void) { unsigned long l; l = 0; *((unsigned short *)&l) = 1; printf("%lu\n", l);

    2热度

    1回答

    我有一个使用std::complex<double>类型的代码。 从FFTW Manual: ,如果你有一个变量 complex<double> *x ,你可以直接通过它通过reinterpret_cast<fftw_complex*>(x)到FFTW。 然而,当我这样做在我的代码: tmp_spectrum = reinterpret_cast<std::complex<double>*>(ff

    3热度

    2回答

    我读过了关于restrict关键字的许多帖子。但实际上,我可以找到的每个示例似乎都只将输入参数引用到函数中,也许只是一个值。我需要澄清我的理解。 我发现一个函数看起来像是完全违反了输入参数和局部变量的关键字规则。 该函数用void *调用到缓冲区,指针声明为_restrict(这是Microsoft Visual C++)。在函数的后面,声明一个类型为UCHAR *的本地变量指针,并使其指向同一个