c++

Re-learn modern C++ resources?

I haven't touch C++ in more then 8 years. I recently had to do fix some C++ code, and although I still can code, I feel like I no more belongs to the camp of C++ programmers. I don't know any libraries, didn't pay attention to the new language features / improvements / best practices. Qt Creator and Qt seems like a nice toolset for what...

Is it safe to delete a void pointer?

Suppose I have the following code: void* my_alloc (size_t size) { return new char [size]; } void my_free (void* ptr) { delete [] ptr; } Is this safe? Or must ptr be cast to char* prior to deletion? ...

Translating 32-bit paths to their WOW64 equivalents

Is there any function that I can call to in a 32-bit app that would convert the paths that it thinks it's using to and from the paths that it's actually using? (For instance, call it to convert the path for a folder in Program Files to a path in Program Files (x86) or vice versa when running on a 64-bit system.) I need to do this so that...

c++ functor and function templates

consider this simple and pointless code. #include <iostream> struct A { template<int N> void test() { std::cout << N << std::endl; } }; int main() { A a; a.test<1>(); } It is a very simple example of a function template. What if however, I wanted to replace A::test with an overloaded operator() to make it a ...

In C/C++ why does the do while(expression); need a semi colon?

My guess is it just made parsing easier, but I can't see exactly why. So what does this have ... do { some stuff } while(test); more stuff that's better than ... do { some stuff } while(test) more stuff ...

How to redefine clog's rdbuf() to be a tee to the original rdbuf() of clog and that of a log file?

Hello, Does anyone have an example of how to redefine the C++ built in clog to instead have a new associated rdbuf() which is processed to be a tee to the original clog.rdbuf() and the rdbuf() of a ofstream object to a log file on disk. The intention is to have the code use the std::clog throughout but to have it go to the both the def...

Are endless loops in bad form?

So I have some C++ code for back-tracking nodes in a BFS algorithm. It looks a little like this: typedef std::map<int> MapType; bool IsValuePresent(const MapType& myMap, int beginVal, int searchVal) { int current_val = beginVal; while (true) { if (current_val == searchVal) return true; MapType::i...

Using pthread_setspecific and pthread_getspecific to store a pointer to a std::map instance.

I'm using a map as a thread specific cache to keep track of failed LDAP searches. I dynamically allocate the map and store the pointer using pthread_setspecific. When checking the cache or incrementing the failure count I use pthred_getspecific in order to retrieve the void* pointer and static_cast the pointer back to my map type. Cal...

Controls on main window using Visual C++ designer?

Is is possible to draw controls using Visual C++ designer on the main window, in the same way you can design dialogs? I'd preferably like to be able to design the main window controls this way without using MFC, rather than creating them on WM_CREATE. EDIT: I don't want a dialog-based app, just to be able to design the main window graph...

What exactly will happen if I disable C++ exceptions in a project?

Visual C++ has a compiler setting "Enable C++ Exceptions" which can be set to "No". What exactly will happen if I set it this way? My code never explicitly throws or catches exceptions (and therefore the first thrown exception will terminate the program anyway) and doesn't rely on stack unwinding - should I expect any more undesired beha...

replace spin lock with signal

Hi, i have alot of spin locks in my multithread code and most of the time they are waiting for other threads to do work and thus chew alot of cpu usage. In linux i normally use pthread_cond_wait and pthread_cond_signal to pause a thread and wake up when signaled. Is there something like this in the boost libraries? Having a quick look i...

Is it a good practice to use unions in C++?

I need to define a class like this: class Color { private: union Data { unsigned int intValue; unsigned char argbBytes[4]; } private: Data m_data; }; Another way is of course define the data as integer and cast it to char array whenever necessary. I'm wondering which one is the preferred way. The contradic...

Printed CDC appears tiny on paper

When I print the CDC for a report control that I've created it appears tiny (less than 1 square inch on paper). How can I get the report to be printed to occupy the entire page ? Or in other words, how can I make the entire report to appear in one printed page. CPrintDialog printDialog(FALSE); printDialog.DoModal(); CDC dc...

Difference between static in C and static in C++??

What is the difference between static in C and static in C++?? ...

gcc optimization flags for Xeon?

Hi, I'd want your input which gcc compiler flags to use when optimizing for Xeons? There's no 'xeon' in mtune or march so which is the closest match? ...

Splitter on a dialog app

how do I create Splitters in an MFC dialog application ? i don't intend to use Doc/View architecture. ...

Is this a memory leak in MFC

// CMyDialog inherits from CDialog void CMyFrame::OnBnClickedCreate() { CMyDialog* dlg = new CMyDialog(); dlg->Create( IDD_MYDIALOG, m_thisFrame ); dlg->ShowWindow( SW_SHOW ); } I'm pretty sure this leaks. What I'm really asking is: is there any "magic" in MFC that does dialog cleanup when the dialog is destroyed. How wo...

How to do massive search and replace in emacs?

Possible Duplicate: Using Emacs to recursively find and replace in text files not already open Duplicate: using-emacs-to-recursively-find-and-replace-in-text-files-not-already-open I need to to regexp search and replace on a list of files. Is there an emacs command (command combo) for that? Or maybe you have a better way to...

copy block of memory

I need a suggestion on on how do I copy a block of memory efficiently, in single attempt if possible, in C++ or assembly language. I have a pointer to memory location and offset. Think of a memory as a 2D array that I need to copy consisting of rows and columns. ...

How to get the address of a value, pointed to by a pointer...

I have a pointer to an int. int index = 3; int * index_ptr = &index; index_ptr is a member variable of a class IndexHandler. class A has a std::vector of IndexHandlers, Avector. class B has a std::vector of pointers to IndexHandlers, Bvector, which I set to point to the items in class A's vector, thusly: Bvector.push_back(Avector[i]...