What would this code do? (memory management)
char *p = new char[200]; char *p1 = p; char *p2 = &p[100]; delete [] p1; Btw this is not a test or anything i actually need to know this :) ...
char *p = new char[200]; char *p1 = p; char *p2 = &p[100]; delete [] p1; Btw this is not a test or anything i actually need to know this :) ...
Im new to network programming and in particular to async-processes. Start also new with the boost-lib Im implementing a class, to access an imap-server. I can send and receive the commands and the response, in general The response is queued in a dequeue inside the class. I put simple the response lines in the queue, for further process...
Hi, this question is related to this one. Given this code char *p = new char[200]; delete[] p; what would happen if you set p[100] = '\0' before deleting p? I had some code where I got a debug error when I tried to delete a not null-terminated char array, something about deleting heap memory that's not assigned. It seemed to delete ...
I'm having trouble with what is apparently a linker error ("undefined reference") in Eclipse / C++. All the classes shown below compile fine, except for one, PlayGame.cpp, which is giving the "undefined reference" error (also shown below). Below are the relevant classes and pieces of code. PlayerFactory.h PlayerFactory.cpp Game.h ...
How can we make a .com file using C/C++? Is it possible? Edit: I was able to successfully make a com file using darin's suggestions. But somehow the exe file of the following program cannot be converted to com file. I get the "File cannot be converted" message by exe2bin. I'm using Borland Turbo C++ 3.0. Any suggestions? #include <dos....
I was changing my for loop to increment using ++i instead of i++ and got to thinking, is this really necessary anymore? Surely today's compilers do this optimization on their own. In this article, http://leto.net/docs/C-optimization.php, from 1997 Michael Lee goes into other optimizations such as inlining, loop unrolling, loop jammin...
Eclipse CDT provides two indexers for C/C++ code (Preferences > C/C++ > Indexer). Does anybody know what the exact difference is between these two? The help file isn't exactly enlightening: "CDT supports the contribution of additional indexers, with 2 indexers being provided with the default CDT release: Fast C/C++ In...
I'm writing a merge sort function, and right now I am just using a test case array (there is no input - this is static, for now). I don't know how to pass an array as an argument. Here is my code right now: //merge sort first attempt #include <iostream> #include <algorithm> #include <vector> int mergeSort(int[]); int main() { int orig...
How can one determine which C or C++ compiler was used to build a particular Windows executable or DLL? Some compilers leave behind version strings in the final executable, but this seems to be rarer on Windows than on Linux. Specifically, I'm interested in distinguishing between Visual C++ and the various MinGW compilers (usually fairl...
Is there any available C++ (or maybe C) function/class/library with only purpose to sanitize a string that might contain HTML? I find a lot of source code for sanitizing in C# or other languages more used in web application but nothing in C++. I'll try to implement my own function if I don't find any available but I think an heavily t...
I'm working on a big app (ns2) and somewhere someone put an exit(1) in there without any debug or print statements and it is being executed. I don't want to have to manually check every file that calls exit to figure out why the program is exiting. Is is possible to determine where the program exited? This is running on Linux and coded i...
Let's say I'm creating an OpenGL game in C++ that will have many objects created (enemies, player characters, items, etc.). I'm wondering the best way to organize these since they will be created and destroyed real-time based on time, player position/actions etc. Here's what I've thought of so far: I can have a global array to store po...
I have been reading up on on steno for a while. I have seen tools that help aid in embedding messages in .mp3's and png's etc. I am familiar that they do this by replacing the least important bit. In images, these LIB are colors that the human eye can't see; thus not needed. In audio files frequencies not audible to the human ear; also n...
Anyone know how to store pointers in a multi-dimensional array? I think that might be the problem that i am having in main: // main.cpp #ifdef _DEBUG #define _CRTDBG_MAP_ALLOC #include <iostream> #include <fstream> #include <string> #endif #include "Word.h" using namespace std; const int WORD_SZ = 100; Word** g_wordArray; int g_arrSz;...
As an extension to this question Are const_iterators faster?, I have another question on const_iterators. How to remove constness of a const_iterator? Though iterators are generalised form of pointers but still const_iterator and iterators are two different things. Hence, I believe, I also cannot use const_cast<> to covert from const_i...
In other words does this work as expected? int32 i = INT_MAX-1; int64 j = i * i; or do I need to cast the i to 64 bit first? ...
Someone here recently brought up the article from Scott Meyers that says: Prefer iterators over const_iterators (pdf link). Someone else was commenting that the article is probably outdated. I'm wondering what your opinions are? Here is mine: One of the main points of the article is that you cannot erase or insert on a const_iterat...
I have tried to keep up with C++ since they introduced 1998 ANSI/ISO C++. I absorbed the new concepts and tried to understand them. I learned about exception handling, templates, and namespaces. I've read about the new cast mechanisms and worked with the STL library. All of these concepts required a lot of energy. But now I am somewhat ...
I am doing a little exploring simulation and I want to show the graphs to compare the performance among the algorithms during run-time. What library comes to your mind? I highly prefer those that come small as I'd love if it's easy for my instructor to compile my code. I've checked gdchart but it seems to be too heavy. I just want a sim...
I am working on a group senior project for my university and I have run into a major hurdle in trying to get my code to work. The compiler that we have for our 8 bit Atmel microcontroller does not support the new or delete operators, and it does not support the C++ STL. I could program it in C, but I have to implement an A* algorithm w...