c++

How can I create a thread-safe singleton pattern in Windows?

I've been reading about thread-safe singleton patterns here: http://en.wikipedia.org/wiki/Singleton_pattern#C.2B.2B_.28using_pthreads.29 And it says at the bottom that the only safe way is to use pthread_once - which isn't available on Windows. Is that the only way of guaranteeing thread safe initialisation? I've read this thread on ...

What's the best stable C++ IDE with a GUI that runs on linux?

What's the best stable C++ IDE with a GUI that runs on linux? ...

"invalid use of incomplete type" error with partial template specialization

The following code: template <typename S, typename T> struct foo { void bar(); }; template <typename T> void foo <int, T>::bar() { } gives me the error invalid use of incomplete type 'struct foo<int, T>' declaration of 'struct foo<int, T>' (I'm using gcc.) Is my syntax for partial specialization wrong? Note that if I remove the...

printf + uint_64 on Solaris 9?

I have some c(++) code that uses sprintf to convert a uint_64 to a string. This needs to be portable to both linux and Solaris. On linux we use %ju, but there does not appear to be any equivalent on Solaris. The closest I can find is %lu, but this produces incorrect output. Some sample code: #include <stdio.h> #include <sys/types.h>...

How do I improve compiling speed in Visual Studio C++ 2003 project that is using C++ Boost Libraries

I have just started using Boost 1.36. These libraries would be very useful in reducing the amount of code needed in the unmanaged C++ software project that I am working on. However when I tried to used these libraries my compile times increased ten fold. This would pretty much offset the productivity gains I would receive by using the l...

How to tell if text on the windows clipboard is ISO 8859 or UTF-8 in C++ ?

I would like to know if there is an easy way to detect if the text on the clipboard is in ISO 8859 or UTF-8 ? Here is my current code: COleDataObject obj; if (obj.AttachClipboard()) { if (obj.IsDataAvailable(CF_TEXT)) { HGLOBAL hmem = obj.GetGlobalData(CF_TEXT); CMemFile sf((BYTE*) ::GlobalLock(hmem),...

How do I create a custom slot in qt4 designer?

I don't know how to do this. Whenever I use the signal/slot editor dialog box, I have to choose from the existing list of slots. So the question is how do I create a custom named slot? Thanks ...

how do I specify the source code directory in VS when looking at the call stack of a memory dump?

I am analyzing a .dmp file that was created and I have a call stack which gives me a lot of info. But I'd like to double click on the call stack and have it bring me to the source code. I can right click on the call stack and select symbol settings.. where I can put the location to the PDB. But there is no option for the source code...

Do programmers of other languages, besides C++, use, know or understand RAII?

I've noticed RAII has been getting lots of attention on Stackoverflow, but in my circles (mostly C++) RAII is so obvious its like asking what's a class or a destructor. So I'm really curious if that's because I'm surrounded daily, by hard-core C++ programmers, and RAII just isn't that well known in general (including C++), or if all thi...

What is the best approach for IPC between Java and C++?

I would like to implement a robust IPC solution between a single JVM app (one process, potentially multiple threads) and a native C++ application that is linked to a C++ dll. The dll may or may not be on the same physical machine. What is the best approach for doing so? Any suggestions will be greatly appreciated! Thanks! ...

Moving between dialog controls in Windows Mobile without the tab key

I have a windows mobile 5.0 app, written in C++ MFC, with lots of dialogs. One of the devices I'm currently targetting does not have a tab key, so I would like to use another key to move between controls. This is fine for buttons but not edit controls or combo boxes. I have looked at a similar question but the answer does not really s...

Tool or code for Cache and Memory Bus performances

I am facing a performance issue on a multi-core (8+) architecture with software written in C++ / VistualStudio / WindowsXP. Suddenly I realized that I have no idea of the performances of my L1 and L2 cache and CPU->to->Memory bandwidth. I have tested several tools (including VTune, Glowcode, etc, etc) but all of them fails when tested ...

value semantics and pointer semantics?

what does it mean by value semantics and what is mean by implicit pointer semantics? ...

#define TRACE(...) doesn't work in C++

I have the following preprocessor divective: #ifndef NDEBUG #define TRACE printf #else #define TRACE(...) #endif and example of usage is: TRACE("TRACE: some parameter = %i\n", param); In C all works perfectly well when I build both debug and release versions, but in C++ compiler emits the following: warning: invalid character in m...

What is returned from a function that returns the return of another function in C++?

If I want to call Bar() instead of Foo(), does Bar() return me a copy (additional overhead) of what Foo() returns, or it returns the same object which Foo() places on the temporary stack? vector<int> Foo(){ vector<int> result; result.push_back(1); return result; } vector<int> Bar(){ return Foo(); } ...

C++: Multithreading and refcounted object

I'm currently trying to pass a mono threaded program to multithread. This software do heavy usage of "refCounted" objects, which lead to some issues in multithread. I'm looking for some design pattern or something that might solve my problem. The main problem is object deletion between thread, normally deletion only decrement the refere...

What are some best practices for OpenGL coding (esp. w.r.t. object orientation)?

This semester, I took a course in computer graphics at my University. At the moment, we're starting to get into some of the more advanced stuff like heightmaps, averaging normals, tesselation etc. I come from an object-oriented background, so I'm trying to put everything we do into reusable classes. I've had good success creating a came...

msbuild: set a specific preprocessor #define in the command line

In a C++ file, I have a code like this: #if ACTIVATE # pragma message( "Activated" ) #else # pragma message( "Not Activated") #endif I want to set this ACTIVE define to 1 with the msbuild command line. It tried this but it doesn't work: msbuild /p:DefineConstants="ACTIVATE=1" Any idea? ...

Using boost in embedded system with memory limitation

Hi, We are using c++ to develop an application that runs in Windows CE 4 on an embedded system. One of our constraint is that all the memory used by the application shall be allocated during startup only. We wrote a lot of containers and algorithms that are using only preallocated memory instead of allocating new one. Do you think it...

"CURLE_OUT_OF_MEMORY" error when posting via https

I am attempting to write an application that uses libCurl to post soap requests to a secure web service. This windows application is built against libCurl version 7.19.0 which, in turn, is built against openssl-0.9.8i. The pertinent curl related code follows: FILE *input_file = fopen(current->post_file_name.c_str(), "rb"); FILE *out...