c++

How do I replace this preprocessor macro with a #include?

UPDATE: Obviously, you'd want to do this using templates or a base class rather than macros. Unfortunately for various reasons I can't use templates, or a base class. At the moment I am using a macro to define a bunch of fields and methods on various classes, like this: class Example { // Use FIELDS_AND_METHODS macro to define some...

shared_ptr: what's it used for

Hi all, I make a lot of use of boost::scoped_ptr in my code and it is great but I'm currently working with software that uses shared_ptr all over the place and I'm wondering if I'm missing something. AFAIK a shared_ptr is only useful if different threads are going to be accessing the same data and you don't know what order the threads...

Multithreading using the boost library

Wish to simultaneously call a function multiple times. I wish to use threads to call a function which will utilize the machines capability to the fullest. This is a 8 core machine, and my requirement is to use the machine cpu from 10% to 100% or more. My requirement is to use the boost class. Is there any way I can accomplish this usi...

Where does gcc look for C and C++ header files?

On a Unix system, where does gcc look for header files? I spent a little time this morning looking for some system header files, so I thought this would be good information to have here. ...

Getting control of the main thread in windows c++ app

I'm writing some code that id like to be able to work with any window, such as a window created through the windows API, MFC, wxWidgets, etc. The problem is that for some things I need to use the same thread that created the window, which in many cases is just sat in a message loop. My first thought was to post a callback message to th...

What is __kernel_vsyscall?

I got a core that looks very different from the ones I usually get - most of the threads are in __kernel_vsyscall() : 9 process 11334 0xffffe410 in __kernel_vsyscall () 8 process 11453 0xffffe410 in __kernel_vsyscall () 7 process 11454 0xffffe410 in __kernel_vsyscall () 6 process 11455 0xffffe410 in __kernel_vsyscall () 5 ...

Is it safe to use STL (TR1) shared_ptr's between modules (exes and dlls)

I know that new-ing something in one module and delete-ing it in another can often cause problems in VC++. Problems with different runtimes. Mixing modules with staticly linked runtimes and/or dynamically linked versioning mismatches both can screw stuff up if I recall correctly. However, is it safe to use VC++ 2008's std::tr1::shared_p...

accessing bitmap resources in a C++ DLL from VB6

I have a C++ DLL including bitmap resources created by Visual Studio. Though I can load the DLL in VB6 using LoadLibrary, I cannot load the image resources either by using LoadImage or by using LoadBitmap. When I try to get the error using GetLastError(), it doesnot return any errors. I have tried using LoadImage and LoadBitmap in anot...

Could anyone suggest a good packet sniffer class for c++?

Could anyone suggest a good packet sniffer class for c++? Looking for a easy insertable class I can use in my c++ program, nothing complicated. ...

Capturing MSN Chat via Memory

Is it possible, or does anyone know the best way to capture MSN chats? I was thinking about attaching to the MSN process, and messing about searching for static addresses for conversations, to capture them. (This is all on the windows platform using c++) ...

Remove all but the last 500,000 bytes from a file with the STL

Our logging class, when initialised, truncates the log file to 500,000 bytes. From then on, log statements are appended to the file. We do this to keep disk usage low, we're a commodity end-user product. Obviously keeping the first 500,000 bytes is not useful, so we keep the last 500,000 bytes. Our solution has some serious performanc...

Should freshers learn Java or C++?

Many of my friends who are graduating from college ask me, "should I learn Java or C++? Which will help me in the long run?" Both languages have their merits and demerits, but what would you guys suggest these college graduates learn? I am sure there is no correct answer for this question, but I would like to get the community opinion...

Efficient Methods for a Life Simulation

Having read up on quite a few articles on Artificial Life (A subject I find very interesting) along with several questions right here on SO, I've begun to toy with the idea of designing a (Very, very, very) simple simulator. No graphics required, even. If I've overlooked a question, please feel free to point it out to me. Like I said, t...

Will .NET take over C/C++ any time?

This is a subjective question. I worked in Visual Basic 6.0 before coming into the .NET space. One thing I see that there are a lot of things, for which there is a need to deal with the Win32 API. As a Visual Basic 6.0 developer, there were a lot of limitations. .NET fixes some of the old problems however the need to rely on Win32 has...

What is the usefulness of project1st<Arg1, Arg2> in the STL?

I was browsing the SGI STL documentation and ran into project1st<Arg1, Arg2>. I understand its definition, but I am having a hard time imagining a practical usage. Have you ever used project1st or can you imagine a scenario? ...

If CHttpConnection::OpenRequest returns NULL how do I find out why

c++ mfc if CHttpConnection::OpenRequest returns a null what can I use to get the internet error. The mfc artical doesn't say what a bad responce looks like. I just said it returns a handle to a CHttpFile. ...

C++ class header files organization

What are the C++ coding and file organization guidelines you suggest for people who have to deal with lots of interdependent classes spread over several source and header files? I have this situation in my project and solving class definition related errors crossing over several header files has become quite a headache. ...

How do you exit from a void function in C++?

How can you prematurely exit from a function if it is a void function? I have a void method that needs to not execute its code if a certain condition is true. I really don't want to have to change the method to actually return a value. ...

Opinions on type-punning in C++?

I'm curious about conventions for type-punning pointers/arrays in C++. Here's the use case I have at the moment: Compute a simple 32-bit checksum over a binary blob of data by treating it as an array of 32-bit integers (we know its total length is a multiple of 4), and then summing up all values and ignoring overflow. I would expect...

Is there a "nice" way to deal with reassembling multicasts from multiple sources?

Hi all I'm currently reworking our existing proprietary socket wrapper code to use boost asio so that it can do some of the heavy lifting for us. Perhaps the most complex area of our existing code is the multicast handling code. The code allows our middle-tier servers (of which there can me many in one system) to send multicasts to c...