I have a simple loop which I've written in C++ as I wanted to profile the performance of a multiply instruction on my CPU. I found some interesting nuances in the assembly code that was generated when I profiled it. Here is the C++ program: #define TESTS 10000000 #define BUFSIZE 1000 uint32_t buf_in1[BUFSIZE]; uint32_t buf_in2[BUFSIZE]; uint32_t volatile buf_out[BUFSIZE]; unsigned int i,
我用C ++编写了一个简单的循环,因为我想分析CPU上乘法指令的性能。 我在分析它时生成的汇编代码中发现了一些有趣的细微差别。 这是C ++程序: #define TESTS 10000000 #define BUFSIZE 1000 uint32_t buf_in1[BUFSIZE]; uint32_t buf_in2[BUFSIZE]; uint32_t volatile buf_out[BUFSIZE]; unsigned int i, j; for (i = 0; i < BUFSIZE; i++) { buf_in1[i] = i; buf_in2[i] = i; } for (j = 0; j < TESTS; j+
I am computing eight dot products at once with AVX. In my current code I do something like this (before unrolling): Ivy-Bridge/Sandy-Bridge __m256 areg0 = _mm256_set1_ps(a[m]); for(int i=0; i<n; i++) { __m256 breg0 = _mm256_load_ps(&b[8*i]); tmp0 = _mm256_add_ps(_mm256_mul_ps(arge0,breg0), tmp0); } Haswell __m256 areg0 = _mm256_set1_ps(a[m]); for(int i=0; i<n; i++
我正在用AVX计算八点产品。 在我目前的代码中,我做了这样的事情(展开之前): 常春藤桥/桑迪桥 __m256 areg0 = _mm256_set1_ps(a[m]); for(int i=0; i<n; i++) { __m256 breg0 = _mm256_load_ps(&b[8*i]); tmp0 = _mm256_add_ps(_mm256_mul_ps(arge0,breg0), tmp0); } Haswell的 __m256 areg0 = _mm256_set1_ps(a[m]); for(int i=0; i<n; i++) { __m256 breg0 = _mm256_load_ps(&am
It seems static_cast take could take value, reference or pointer and convert them to another type of value, reference or pointer. However, it seems dynamic_cast, reinterpret_cast and const_cast can only take reference and pointer . I know for cont_cast, it only take pointer or reference but not variable which is undefined behavior. Not sure why dynamic_cast and reinterpret_cast can only take
看来static_cast可以取值,引用或指针 ,并将它们转换为另一种类型的值,引用或指针。 但是,似乎dynamic_cast,reinterpret_cast和const_cast只能带参考和指针 。 我知道对于cont_cast,它只采用指针或引用,而不是变量,这是未定义的行为。 不知道为什么dynamic_cast和reinterpret_cast只能引用和指针,以及如果对值类型使用dynamic_cast和reinterpret_cast会发生什么。 例如,static_cast可以采取指针 : B* pb; D* pd;
Currently I am working with a legacy c++ code base. In this codebase pointer to objects are converted to void-pointers and then stored in a c-library. Consider the following code: class interface { public: virtual void foo() { std::cout << "Interface" << std::endl;} virtual ~interface(){}; }; class debug_interface: public interface { public: virtual void foo() { std::
目前我正在使用遗留的c ++代码库。 在这个代码库中,指向对象的指针被转换为空指针,然后存储在一个c库中。 考虑下面的代码: class interface { public: virtual void foo() { std::cout << "Interface" << std::endl;} virtual ~interface(){}; }; class debug_interface: public interface { public: virtual void foo() { std::cout << "Debug Interface" << std::endl;} }; 对象
No. This question in NOT duplicate of When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used? The question asked here is no ways similar to the link described as duplicate. First question : I am using const_cast below for two cases. one of it works. the other doesn't. 1. int* const //Works. In this syntax the address to which the variable would point to canno
不是。这个问题的重复时间应该是static_cast,dynamic_cast,const_cast和reinterpret_cast何时使用? 这里提出的问题与描述为重复的链接没有任何相似之处。 第一个问题:我使用下面的const_cast两种情况。 其中一个作品。 另一个没有。 1. int * const //工作。 在此语法中,变量将指向的地址不能更改。 所以我使用const_cast作为下面,它的工作原理: ` int j=3; int *k=&j; int *m=&j; int* const i=k; c
I am trying to create a template class that contains a pointer to an arbitrary class instance and function as follows: template<class C> class A { typedef void (C::*FunctPtr)(); //e.g. void C::some_funct(); FunctPtr functPtr_; C* instPtr_; public: A(FunctPtr functPtr, C* instPtr) : functPtr_(functPtr) , instPtr_(instPtr) {} }; However, I want to be able to create
我试图创建一个模板类,其中包含一个指向任意类实例和函数的指针,如下所示: template<class C> class A { typedef void (C::*FunctPtr)(); //e.g. void C::some_funct(); FunctPtr functPtr_; C* instPtr_; public: A(FunctPtr functPtr, C* instPtr) : functPtr_(functPtr) , instPtr_(instPtr) {} }; 但是,我希望能够创建此类的实例,而无需使用放置新动态内存分配。 C ++标准是否保证这
I was reading about const_cast operator in c++ 1.First weird thing thing i can't understand is const_cast operator syntax ie -const_cast--<--Type-->--(--expression--)-------------------->< what i have understand about this syntax is that it helps to cast away constness of an expression of type Type .But consider this code class ConstTest { private: int year; publ
我正在阅读关于c ++中的const_cast运算符 我不明白的第一件奇怪的事情是 const_cast运算符语法即 -const_cast - < - 类型 - > - ( - 表达 - )--------------------> < 我对这个语法的理解是,它有助于抛弃类型为Type的expression的常量。但请考虑此代码 class ConstTest { private: int year; public: ConstTest() : year(2007) {} void printYear() const; }; int main() { Co
Possible Duplicate: Why do we have reinterpret_cast in C++ when two chained static_cast can do it's job? I have been suggested that i should not use reinterpret_cast or const_cast in case of pointer to pointer conversion. Only dynamic_cast should be used.Because other cast can create problem in future. So my question is why not reinterpret_cast or other cast which is dangerous has been
可能重复: 当两个链接的static_cast可以完成它的工作时,为什么我们在C ++中使用reinterpret_cast? 我已经建议我不应该在指针转换指针的情况下使用reinterpret_cast或const_cast。 只有dynamic_cast应该使用。因为其他演员将来可能会产生问题。 所以我的问题是为什么reinterpret_cast或其他强制转换已经从c ++标准中删除。 因为有时候你需要一个能够完成reinterpret_cast的演员reinterpret_cast 。 至于dynamic_cast
I've read various previous questions about the use of reinterpret_cast , and I've also read the relevant wording in the C++ standard. Essentially, what it comes down to is that the result of a pointer-to-pointer reinterpret_cast operation can't safely be used for anything other than being cast back to the original pointer type. In practice, however, most real-world uses of reinterp
我读过关于reinterpret_cast使用的各种先前的问题,并且我还阅读了C ++标准中的相关措辞。 实质上,它的缺点是指针指针reinterpret_cast操作的结果不能安全地用于除了被转换回原始指针类型以外的其他任何内容。 然而,在实践中, reinterpret_cast大多数真实世界的使用似乎基于reinterpret_cast与C风格演员相同的(错误)假设。 例如,我已经看到很多使用reinterpret_cast从char*为unsigned char*的代码,用于字符集转换例程
First of all, this is not a duplicate of Why do we have reinterpret_cast in C++ when two chained static_cast can do it's job?. I know situations where we cannot use even two chained static_cast to achieve that, what reinterpret_cast does. But is there any situation where I should prefer a two chained static_cast over a simple and more readable reinterpret_cast ? reinterpret_cast should b
首先,这不是重复的为什么当两个链接的static_cast可以完成它的工作时,我们在C ++中使用reinterpret_cast ?. 我知道甚至不能使用两个链接的static_cast来实现这一点, reinterpret_cast做什么。 但是有没有什么情况下我应该更喜欢两个链接的static_cast不是一个简单且更易读的reinterpret_cast ? reinterpret_cast应该是一个巨大的闪烁符号,说这个疯狂的疯狂,但我知道我在做什么。 不要仅仅因为懒惰而使用它。 reint