Stringize operator failure

The C and C++ standards all include text to the effect that if a stringize operation fails to produce a valid string literal token, the behavior is undefined. In C++11 this is actually possible, by including a newline character in a raw string literal. But the catch-all has always been there in the standards. Is there any other way that stringize can produce UB, where UB or an ill-formed prog

使操作失败

C和C ++标准都包含文字,表明如果字符串操作无法生成有效的字符串文字标记,则行为是未定义的。 在C ++ 11中,这实际上是可行的,通过在原始字符串文字中包含换行符。 但是标准中总是存在一揽子标准。 有没有其他方式可以产生UB,UB还是一个不合格的程序尚未发生? 我有兴趣听听有关C或C ++的任何方言。 我在写预处理器。 stringify( # )运算符只能在字符串常量中转义 。 事实上, 除了在行尾之外,并没有特别的意义

Getting "actual" registers from MCInsts (x86)

I'm using llvm-mc with the goal of making a relatively smart disassembler (identifying and tracking locals, easily following branches, etc), and part of that is creating a string representation of the disassembled instructions. When I started this, I expected that I would be able to relatively easily identify registers and values used by MCInst s and whip out another representation myself w

从MCInsts(x86)获取“实际”寄存器

我使用的是llvm-mc,目标是制作一个相对聪明的反汇编程序(识别和跟踪本地,轻松跟踪分支等),其中一部分是创建反汇编指令的字符串表示。 当我开始这项工作时,我希望能够相对容易地识别MCInst所使用的寄存器和值,并自己抽出另一个表示,我可以轻松地处理这些表示。 然而,经过一番调查后,我意识到,显示的操作数与指令的文本表示以及实际存在于MCInst对象内的操作数之间的相关性相当低。 以下是一些示例(英特尔语法):

Does anybody know what this C++ inline assembly does?

I've seen the following code in an open source windows tool called DM2. #define OEP_ASM __asm jmp OEP __asm _emit 0x5B __asm _emit 0x66 __asm _emit 0x6C __asm _emit 0x79 __asm _emit 0x66 __asm _emit 0x61 __asm _emit 0x6E __asm _emit 0x63 __asm _emit 0x79 __asm _emit 0x26 __asm _emit 0x57 __asm _emit 0x65 __asm _emit 0x69 __asm _emit 0x72 __asm _emit 0x64 __asm _emit 0x5D __asm _emit 0x

有人知道这个C ++内联程序集是干什么的吗?

我在一个名为DM2的开源Windows工具中看到了以下代码。 #define OEP_ASM __asm jmp OEP __asm _emit 0x5B __asm _emit 0x66 __asm _emit 0x6C __asm _emit 0x79 __asm _emit 0x66 __asm _emit 0x61 __asm _emit 0x6E __asm _emit 0x63 __asm _emit 0x79 __asm _emit 0x26 __asm _emit 0x57 __asm _emit 0x65 __asm _emit 0x69 __asm _emit 0x72 __asm _emit 0x64 __asm _emit 0x5D __asm _emit 0x00 __asm OEP: 有没有意

MOV Instruction for Registers

So I am running _asm with C++ using Visual Studio. So I am new to assembly programming, I am following a textbook and know that the general register EAX holds 32 bits and AX is 16 with AL, AH being low/high. So how would I move multiple commands using only the MOV instruction. I tried doing MOV AL, 'a', 'c' , 'e' but I get illegal amount of operands. Thats only 3 so shouldn't AL be ab

MOV寄存器指令

所以我使用Visual Studio运行_asm与C ++。 所以我是汇编程序设计新手,我正在学习一本教科书,并且知道通用寄存器EAX保存32位,AX是16,AL是AH,AH是低/高。 那么,我将如何仅使用MOV指令来移动多个命令。 我尝试过 MOV AL, 'a', 'c' , 'e' 但是我得到了非法的操作数。 那只有3个,所以不应该保持这个价值? 我在做之后尝试 MOV EAX, 0 MOV AL, 'a', 'c' , 'e' 那么我将如何移动三个不同的值,甚至更像12个字母到8位

x86 assembly instructions optimisation

I'm trying to optimize a block of instructions in a loop, called thousands of time, which is the bottleneck in my algorithm. This block of code compute the multiplication of a N matrices 3x3 (iA array) against N vectors 3 (iV array) and store the N results in oV array. (N is not fix and is usually between 3000 and 15000) Each line of matrices and vectors are 128-bits aligned (4 floats) t

x86汇编指令优化

我试图优化一个循环中的一段指令,称为数千次,这是我算法的瓶颈。 该代码块计算N个矩阵3x3(iA阵列)与N个向量3(iV阵列)的相乘并将N个结果存储在oV阵列中。 (N不固定,通常在3000到15000之间) 每行矩阵和向量都是128位对齐的(4个浮点数),以利用SSE优化(忽略第四个浮点值)。 C ++代码: __m128* ip = (__m128*)iV; __m128* op = (__m128*)oV; __m128* A = (__m128*)iA; __m128 res1, res2, res3; int

MSVCs Implementation of std::put

I am working with Microsoft Visual Studio 2012, and was looking at using std::put_time , so I created the following example: int main() { std::time_t t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); std::locale::global( std::locale("en-GB") ); std::cout << std::put_time( std::localtime( &t ), "%x" ) << std::endl; } This produces the follo

MSVCs执行std :: put

我正在使用Microsoft Visual Studio 2012,并且正在使用std::put_time ,因此我创建了以下示例: int main() { std::time_t t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); std::locale::global( std::locale("en-GB") ); std::cout << std::put_time( std::localtime( &t ), "%x" ) << std::endl; } 这会产生以下输出: 06/25/2013 这不是我所期望的en-GB语

C libcurl, limit download speed

I have problem with CURLOPT_MAX_RECV_SPEED_LARGE api man page. I want to set max download speed, so i added: curl_off_t max_speed = 1000*25; curl_easy_setopt(curl_handle, CURLOPT_MAX_RECV_SPEED_LARGE, max_speed); But problem is when it hit the limit (25kB/s) or what I set up, the CPU usage goes 100% Am I using it wrong way? I guess, because I haven't find this problem anywhere. I trie

C libcurl,限制下载速度

我CURLOPT_MAX_RECV_SPEED_LARGE api手册页的问题。 我想设置最大下载速度,所以我补充说: curl_off_t max_speed = 1000*25; curl_easy_setopt(curl_handle, CURLOPT_MAX_RECV_SPEED_LARGE, max_speed); 但问题是,当它达到极限(25kB / s)或我设置的时候, CPU使用率达到100% 我用错了吗? 我想,因为我没有在任何地方发现这个问题。 我试图将这两行添加到原始示例代码中,但它也变得疯狂。 我正在使用Windows和li

Temporary lifetime extension

The 12.2.5 section of standard says: A temporary bound to a reference parameter in a function call (5.2.2) persists until the completion of the full expression containing the call. A temporary bound to the returned value in a function return statement (6.6.3) persists until the function exits. In all these cases, the temporaries created during the evaluation of the expression initializing the

临时寿命延长

标准的12.2.5节说: 临时绑定到函数调用中的引用参数(5.2.2)直到完成包含调用的完整表达式。 函数返回语句(6.6.3)中的返回值的临时绑定一直存在,直到函数退出。 在所有这些情况下,在初始化引用的表达式(除引用被绑定到的临时表达式)的评估期间创建的临时对象在创建它们的完整表达式的末尾被销毁,并且以与其相反的顺序他们的建设完成。 我试图理解的代码是: #include <iostream> const int& foo(const

Undefined reference to static class member

Can anyone explain why following code won't compile? At least on g++ 4.2.4. And more interesting, why it will compile when I cast MEMBER to int? #include <vector> class Foo { public: static const int MEMBER = 1; }; int main(){ vector<int> v; v.push_back( Foo::MEMBER ); // undefined reference to `Foo::MEMBER' v.push_back( (int) Foo::MEMBER ); /

对静态类成员的未定义引用

任何人都可以解释为什么下面的代码不会编译? 至少在g ++ 4.2.4上。 更有趣的是,为什么当我将MEMBER投射到int时会编译? #include <vector> class Foo { public: static const int MEMBER = 1; }; int main(){ vector<int> v; v.push_back( Foo::MEMBER ); // undefined reference to `Foo::MEMBER' v.push_back( (int) Foo::MEMBER ); // OK return 0; } 您需要实际

Why should exceptions be used conservatively?

Possible Duplicate: Why is exception handling bad? I often see/hear people say that exceptions should only be used rarely, but never explain why. While that may be true, rationale is normally a glib: "it's called an exception for a reason" which, to me, seems to be the sort of explanation that should never be accepted by a respectable programmer/engineer. There is a range of

为什么应该保守地使用例外?

可能重复: 为什么异常处理不好? 我经常看到/听到有人说异常应该很少使用,但永远不能解释为什么。 虽然这可能是正确的,但基本原理通常是一种滑稽的说法:“这被称为例外,这对我来说似乎是一种应该永远不会被可敬的程序员/工程师接受的解释。 有一系列问题可以使用例外来解决。 为什么将它们用于控制流是不明智的? 在如何使用它们方面非常保守,背后的哲学是什么? 语义? 性能? 复杂? 美学? 惯例? 我之