c++

Works on debug but not release

I have a thread that sets a value to true when it is done. Until then I wait: while(1) { if(done[0] == true) { break; } } This code works just fine in Debug but in Release it stays in the loop forever even though the debugger clearly says that it is true and not false. Why would this not work? Thanks ...

Using an iterator without its container

I am mixing some C and C++ libraries and have only a single pointer available to do some work in a callback function. All I need to do is iterate through a vector. Here's a simplified, untested example: bool call_back(void* data){ done=... if (!done) cout << *data++ << endl; return done; } Note that this function is in an ext...

one line assert to test if STL container is sorted

Is there a way to write a one line condition that would return true if STL container is sorted? The container in question is std::vector I intend to use it in an assert ...

Help with AA-tree insertion - problems with skew() and split() in loop

Hello all, I am doing an STL-like AA-tree as a personal project and am running into some trouble. Chopping out the loop containing the skew and split functions gives a working and correct unbalanced binary search tree. However, once the loop is included it goes into an infinite loop. I am trying to insert the numbers 0 to 49 and the ske...

Gzip In-Memory Compression

Quick and simple question. There are examples online about achieving in-memory gzip compression with zlib (C++) WITHOUT external libraries (like boost or such)? I just need to compress and decompress a block of data without much options. (it must be gzip as its the same format used by another mine C# program (the data is to be shared)...

Operators vs Functions in C/C++

Someone recently asked me the difference between a C++ standard operator (e.g. new,delete,sizeof) and function (e.g. tan,free, malloc). By "standard" I mean those provided by default by the compiler suite, and not user defined. Below were the answers I gave, though neither seemed satisfactory. (1) An operator doesn't need any headers ...

How do I insert format str and don't remove the matched regular expression in input string in boost::regex_replace() in C++?

I want to put space between punctuations and other words in a sentence. But boost::regex_replace() replaces the punctuation with space, and I want to keep a punctuation in the sentence! for example in this code the output should be "Hello . hi , " regex e1("[.,]"); std::basic_string<char> str = "Hello.hi,"; std::basic_string<char> fmt ...

Critical section initialization when creating thread-safe singleton (C++)

I'm trying to do the same thing as suggested in this solution: http://stackoverflow.com/questions/164496/how-can-i-create-a-thread-safe-singleton-pattern-in-windows/164640#164640 But, where should the critical section be initialized and uninitialized? ...

The C++ 'new' keyword and C

Possible Duplicate: Use the keyword class as a variable name in C++ In a C header file of a library I'm using one of the variables is named 'new'. Unfortunately, I'm using this library in a C++ project and the occurence of 'new' as a variable names freaks out the compiler. I'm already using extern "C" { #include<...> }, but th...

Image manipulation library for mobile application

I need a C/C++ image manipulation library for mobile image application, The library should have Brightness/contrast Levels Effects - Grayscale, Sepia and so on I particularly want to use it on Samsung BADA Platform. I want the the one event hough if it is not optimized for BADA ...

delete,copy,rename files and directories in WINAPI ..?

hi I made a code that search in a givin path for a certain file name or folder and print the value BUT now how can i modify it to instead of printing its name perform on of the operations ( delete,copy,rename ) I searched on google and found nothin. #include "stdafx.h" #include <windows.h> int _tmain(int argc, _TCHAR* argv[]) { TC...

How to address thread-safety of service data used for maintaining static local variables in C++?

Consider the following scenario. We have a C++ function with a static local variable: void function() { static int variable = obtain(); //blahblablah } the function needs to be called from multiple threads concurrently, so we add a critical section to avoid concurrent access to the static local: void functionThreadSafe() { ...

How to use Application Verifier to find memory leaks

I want to find memory leaks in my application using standard utilities. Previously I used my own memory allocator, but other people (yes, you AlienFluid) suggested to use Microsoft's Application Verifier, but I can't seem to get it to report my leaks. I have the following simple application: #include <iostream> #include <conio.h> class...

Thread-safe initialization of function-local static const objects

This question made me question a practice I had been following for years. For thread-safe initialization of function-local static const objects I protect the actual construction of the object, but not the initialization of the function-local reference referring to it. Something like this: namspace { const some_type& create_const_th...

How to integrate C++ function that can throw the MyException in swig interface file

Hi, I am new to swig,using swig for integrating c++ code to Perl,I have c++ function like void s() throw MyException. How i can integrate the c++ function that can throw the MyException in the swig interface file.How i can called the c++ function in Perl. Any Help in this regard is highly appreciated. ...

C++ convert formatted string to a stream

Hi All, I'm using VS2008 C++. As I understand it there is no way to pass something like this in a C++ stream : (without using external libraries) "number " << i <------ when i is an integer. So I was looking for a better way to do this, and I all I could come up with is create a string using : char fullstring = new char[10]; spr...

How can I change font leading (linespacing) in wxWidgets?

Then I use wxDC::DrawLabel for drawing multiline text I want to control font leading (linespacing). Is it possible? ...

Is there performance to be gained by moving storage allocation local to a member function to its class?

Suppose I have the following C++ class: class Foo { double bar(double sth); }; double Foo::bar(double sth) { double a,b,c,d,e,f a = b = c = d = e = f = 0; /* do stuff with a..f and sth */ } The function bar() will be called millions of times in a loop. Obviously, each time it's called, the variables a..f have to be allocated....

UIDs for data objects in MySQL

Hi there, I am using C++ and MySQL. I have data objects I want to persist to the database. They need to have a unique ID for identification purposes. The question is, how to get this unique ID? Here is what I came up with: 1) Use the auto_increment feature of MySQL. But how to get the ID then? I am aware that MySQL offers this "SELEC...

How to use cppcheck's inline suppression filter option for C++ code?

I would like to use cppcheck for static code analysis of my C++ code. I learned that I can suppress some kind of warnings with --inline-suppr command. However, I can find what "suppressed_error_id" I should put in the comment: // cppcheck-suppress "suppressed_error_id" ...