Common reasons for bugs in release version not present in debug mode

错误和异常程序行为的典型原因是什么,它们仅在释放编译模式下表现出来,但在调试模式下不会发生? Many times, in debug mode in C++ all variables are null initialized, whereas the same does not happen in release mode unless explicitly stated. Check for any debug macros and uninitialized variables Does your program uses threading, then optimization can also cause some issues in release mode. Also

在调试模式下,发布版本中缺陷的常见原因不存在

错误和异常程序行为的典型原因是什么,它们仅在释放编译模式下表现出来,但在调试模式下不会发生? 很多时候,在C ++的调试模式下,所有变量都是空初始化的,而除非明确说明,否则在释放模式下不会发生相同的变化。 检查任何调试宏和未初始化的变量 您的程序是否使用线程,然后优化也会在发布模式中导致一些问题。 同时检查所有异常,例如与发布模式没有直接关系,但有时我们忽略了一些重要的异常,例如VC ++中的mem访问冲

c++

I am working on a project based on a custom-defined data structure list_t in C++. Here is the predefined functions that would help me manipulate this list_t and the function I am asked to write which is called insert_list(list_t, list_t, int) is to be tail-recursive. typedef Recursive_list list_t; // EFFECTS: returns true if list is empty, false otherwise bool list_isEmpty(const list_t& li

C ++

我正在C ++中基于自定义数据结构list_t开发项目。 这里是预定义的函数,它可以帮助我操作这个list_t,并且我被要求写入的函数被称为insert_list(list_t,list_t,int)是尾递归的。 typedef Recursive_list list_t; // EFFECTS: returns true if list is empty, false otherwise bool list_isEmpty(const list_t& list); // EFFECTS: returns an empty list. list_t list_make(); // EFFECTS: given the list (list) ma

Which, if any, C++ compilers do tail

It seems to me that it would work perfectly well to do tail-recursion optimization in both C and C++, yet while debugging I never seem to see a frame stack that indicates this optimization. That is kind of good, because the stack tells me how deep the recursion is. However, the optimization would be kind of nice as well. Do any C++ compilers do this optimization? Why? Why not? How do I go

如果有的话,哪些C ++编译器会做尾巴

在我看来,它可以非常好地在C和C ++中进行尾递归优化,但在调试时我似乎没有看到指示此优化的帧堆栈。 这很好,因为堆栈告诉我递归有多深。 但是,优化也会很好。 是否有任何C ++编译器可以做这种优化? 为什么? 为什么不? 我该如何去告诉编译器这样做? 对于MSVC:/ O2或/ Ox 对于GCC:-O2或-O3 如何检查编译器是否在特定情况下完成了这项工作? 对于MSVC,启用PDB输出以便能够跟踪代码,然后检查代码 对于

Intended infinite recursion, no

Infinite recursion is most often not desired, and when it happens it usually causes a stack overflow or segfaults. But for theory's sake, and plain curiosity, I've been thinking if it'd be possible to create actual infinite recursion, intentionally. Working in C++ and C where the stack, usually, grows for each function call, and each function returns and pops the part of the stack

预期的无限递归,没有

无限递归通常是不需要的,当它发生时,通常会导致堆栈溢出或段错误。 但是出于理论和朴素的好奇心,我一直在考虑是否可以有意地创建实际的无限递归。 使用C ++和C工作,通常每个函数调用都会增加堆栈,每个函数都会返回并弹出它处理的堆栈部分。 这是这个想法。 是否有可能强制函数清除它自己的堆栈空间,然后调用另一个函数,以便新函数有效替换第一个函数,而不需要第一个函数需要返回,然后通过循环再次启动。 如果

Custom implementation of malloc in C++

I came across an interview question where they asked to implement malloc() and free function in C++ . At the very beginning a char array of size 50000 is declared(50000 bytes). Assuming this is the heap memory, write malloc and free functions to allocate blocks of memory and free up memory. Any one can provide me with C++ working/pseudo code or just explain the mechanism? (obviously code wo

在C ++中定制实现malloc

我遇到了一个采访问题,他们要求在C ++中实现malloc()和free函数。 最初声明一个大小为50000的字符数组(50000字节)。 假设这是堆内存,请编写malloc和free函数来分配内存块并释放内存。 任何人都可以提供给我C ++工作/伪代码或者只是解释机制? (显然,代码会使它更容易理解)。 谢谢,Rohit 编写生产级动态内存分配器是一项非常艰巨的任务,编写一个玩具很简单。 这个问题显然是为了测试你的技能,但在别人的作

How is heap usually implemented?

Possible Duplicate: How is heap and stack memories managed, implemented, allocated? Hi, my question is about heap, not the data structure, but the area of memory that is used for dynamic memory allocation. Suppose we're writing a program in C (or maybe C++) and somewhere in the depths of its code a call to malloc() is made (or operator new is invoked, in case of C++). Now what is the l

通常如何实现堆?

可能重复: 如何管理,实施和分配堆和堆栈内存? 嗨,我的问题是关于堆,而不是数据结构,但用于动态内存分配的内存区域。 假设我们用C语言(或者C ++)编写程序,并且在其代码的深处某处调用malloc()(或者在C ++的情况下调用operator new)。 现在分配的内存的位置是什么? 编译器(链接器?)是否添加用作堆的数据段? 该细分受众群的规模如何确定? 如果我们尝试分配比整个“堆段”更大的内存块,会发生什么? 堆

Some memory seems to be left allocated after malloc() and free()

I am new to C. I am trying to get comfortable with malloc + free. I have coded following test but for some reason the memory isn't freed completely (top still indicates about 150MB of memory allocated to process). Why is that? #include <stdio.h> #include <malloc.h> typedef struct { char *inner; } structure; int main() { int i; structure** structureArray; stru

一些内存似乎在malloc()和free()之后被分配

我是C新手。我试图让malloc +免费。 我编写了下面的测试代码,但由于某种原因,内存未完全释放(最高仍然表示分配给进程的内存大约为150MB)。 这是为什么? #include <stdio.h> #include <malloc.h> typedef struct { char *inner; } structure; int main() { int i; structure** structureArray; structureArray = (structure**)malloc(sizeof(structure*)*1000*10000); for (i = 0; i &

based virtual machine function call/return implementation issues

Today I decided to create a little stack-based virtual machine in C++11 for fun - everything was going pretty well until I got to function calling and returning from functions. I've been trying to follow calling guidelines similar to x86 assembly but I'm getting really confused. I have trouble dealing with stack base pointer offsets and with return values. It seems very hard to keep

基于虚拟机的函数调用/返回实现问题

今天,我决定在C ++ 11中创建一个基于堆栈的小型虚拟机,以获得更多的乐趣 - 在函数调用和函数返回之前,一切都非常顺利。 我一直在尝试遵循类似于x86汇编的调用指导原则,但我感到非常困惑。 我无法处理堆栈基址指针偏移量和返回值。 看起来很难跟踪堆栈上用于返回值和参数(用于函数调用)的寄存器。 我创建了一个简单的汇编语言和编译器。 这是一个评论示例(我的虚拟机编译并执行)。 我试图解释发生了什么,并在

How are the function local variables accessed from the stack?

From http://www.learncpp.com/cpp-tutorial/79-the-stack-and-the-heap/ Here is the sequence of steps that takes place when a function is called: The address of the instruction beyond the function call is pushed onto the stack. This is how the CPU remembers where to go after the function returns. Room is made on the stack for the function's return type. This is just a placeholder for now

函数局部变量如何从堆栈中访问?

从http://www.learncpp.com/cpp-tutorial/79-the-stack-and-the-heap/ 这是调用函数时发生的一系列步骤: 超出函数调用的指令地址被压入堆栈。 这是CPU如何记住函数返回后的位置。 房间在函数返回类型的堆栈上进行。 目前这只是一个占位符。 CPU跳转到该函数的代码。 当前的堆栈顶部被保存在一个称为堆栈帧的特殊指针中。 此点之后所有添加到堆栈的内容都被认为是本地的。 所有的函数参数都放在堆栈上。 函数

Safely override C++ virtual functions

I have a base class with a virtual function and I want to override that function in a derived class. Is there some way to make the compiler check if the function I declared in the derived class actually overrides a function in the base class? I would like to add some macro or something that ensures that I didn't accidentally declare a new function, instead of overriding the old one. Take

安全地覆盖C ++虚拟功能

我有一个虚拟函数的基类,我想在派生类中重写该函数。 有什么方法可以让编译器检查我在派生类中声明的函数是否实际覆盖了基类中的函数? 我想添加一些宏,或者确保我没有意外声明一个新函数,而不是覆盖旧函数。 以这个例子: class parent { public: virtual void handle_event(int something) const { // boring default code } }; class child : public parent { public: virtual void handle_event(int somet