c++

Browser agnostic C++ DOM interface

When programming in C++ against the browser's DOM each engine has a different set of interfaces, IE has the COM based MSHTML, Mozilla has the XPCOM based Gecko DOM etc. Is there a common API that has adapters for major browsers (and versions)? As a clarification, the application in question is a desktop application written in C++ wh...

How to correctly benchmark a [templated] C++ program

Hi, < backgound> I'm at a point where I really need to optimize C++ code. I'm writing a library for molecular simulations and I need to add a new feature. I already tried to add this feature in the past, but I then used virtual functions called in nested loops. I had bad feelings about that and the first implementation proved that th...

Is there any way to check if an iterator is valid?

For two threads manipulating a container map for example, what the correct way to test whether an iterator still valid (for performance reason) ? Or would be of only indirect way that this can be done. The sample code for this : #define _SECURE_SCL 1 //http://msdn2.microsoft.com/en-us/library/aa985973.aspx #define _SECURE_SCL_THROWS 1 ...

How to get Webkit bugs fixed?

Webkit has a few bugs that prevent our software from running in this browser (and Safari/Chrome/etc). We don't have sufficient C++ knowledge to fix the bugs ourselves, but we're certainly willing to fund the development and do extensive testing of the patches. What would be the best way to proceed? I was thinking of submitting a project...

Emptying a C++ object

Often I add an Empty method to my C++ objects to clear the internal state using code similar to the following. class Foo { private: int n_; std::string str_; public: Foo() : n_(1234), str_("Hello, world!") { } void Empty() { *this = Foo(); } }; This seems to be better than duplicating code in t...

Best way to safely printf to a string?

Does anyone know a good safe way to redirect the output of a printf-style function to a string? The obvious ways result in buffer overflows. Something like: string s; output.beginRedirect( s ); // redirect output to s ... output.print( "%s%d", foo, bar ); output.endRedirect(); I think the problem is the same as asking, "how many c...

Linux C++ Debugger

I'm looking for the perfect Linux C++ debugger. I don't expect success, but the search should be informative. I am a quite capable gdb user but STL and Boost easily crush my debugging skills. It not that I can't get into the internals of a data structure, it's that it takes so long I usually find another way( "when in doubt, print it ...

char!=(signed char), char!=(unsigned char)

The code below compiles, but has different behavior for the char type than for the int types. In particular cout << getIsTrue< isX<int8>::ikIsX >() << endl; cout << getIsTrue< isX<uint8>::ikIsX >() << endl; cout << getIsTrue< isX<char>::ikIsX >() << endl; result in 3 instantiations of templates for three types: int8, uint...

Quick and dirty operator!=

In my classes I often write a quick operator!= by returning !(*this == rhs), e.g.: class Foo { private: int n_; std::string str_; public: ... bool operator==(const Foo& rhs) const { return n_ == rhs.n_ && str_ == rhs.str_; } bool operator!=(const Foo& rhs) const { return !(*this == rhs); ...

How can I guarantee catching a EXCEPTION_STACK_OVERFLOW structured exception in C++ under Visual Studio 2005?

Background I have an application with a Poof-Crash[1]. I'm fairly certain it is due to a blown stack. The application is Multi-Threaded. I am compiling with "Enable C++ Exceptions: Yes With SEH Exceptions (/EHa)". I have written an SE Translator function and called _set_se_translator() with it. I have written functions for and set...

C++ lifetime management of encapsulated objects

What is the best approach to encapsulate objects and manage their lifetime? Example: I have a class A, that contains an object of type B and is solely responsible for it. Solution 1, clone b object to ensure that only A is able to clean it up. class A { B *b; public: A(B &b) { this->b = b.clone(); } ~A() ...

Can someone explain this template code that gives me the size of an array?

template<typename T, size_t n> size_t array_size(const T (&)[n]) { return n; } The part that I don't get is the parameters for this template function. What happens with the array when I pass it through there that gives n as the number of elements in the array? ...

Friend scope in C++

If I have three classes, A, B, C. A and B are friends (bidirectionally). Also, B and C are friends (bidirectionally). A has a pointer to B and B has a pointer to C. Why can't A access C's private data through the pointer? Just to clarify: This is a pure theoretical C++ language question, not a design advice question. ...

C/C++ environment initialization

A co-worker just asked me if it was safe to use getenv() in static initializers, that is, before main(). I looked in Stevens, and in the Posix Programmer's Guide, and the best I can find is An array of strings called the enviroment is made available when the process begins. This array is pointed to by the external variable environ,...

C++ Builder or Visual Studio for native C++ development?

I've decided I want to get more into native code development with C++. I'm trying to decide if I would be better served using CodeGear C++ Builder 2009 or Visual Studio 2008. I currently use Delphi 2007, so I'm very comfortable with C++ Builder's IDE (its the same as Delphi), as well as the VCL and RTL. I've never been a big fan of MFC ...

Is there a way to find all the functions exposed by a dll

I've been searching for a way to get all the strings that map to function names in a dll. I mean by this all the strings for which you can call GetProcAddress. If you do a hex dump of a dll the symbols (strings) are there but I figure there must me a system call to acquire those names. ...

Reduce windows executable size

I have a C++/MFC app on windows - dynamically linked it's only 60kb static it's > 3Mb. It is a being distributed to customers by email and so needs to be as small as possible. It statically links the MFC and MSCVRT libraries - because it is a fix to some problems and I don't want more support calls about missing libs - especially the...

Environment overrides for Linux linker/loader

Earlier today I asked a question about environ, and one of the more interesting replies suggested that I could gather information using LD_DEBUG. Now I've known about some linker/loader environment variables (such as *LD_PRELOAD*) for awhile, but this one was new to me. Googling, I found a Linux-specific man page discussing environment ...

boost source code

Is there any way to get the boost libraries source code? I have browsed the SVN repository and I could see only HPP files. No source files are available there. I would like to look into the source code for "shared_ptr". Can anyone guide me? Also from where can I download BCP utility? ...

STL __merge_without_buffer algorithm?

Where can I get a decent high-level description of the algorithm used in __merge_without_buffer() in the C++ STL? I'm trying to reimplement this code in the D programming language, with some enhancements. I can't seem to grok what it's doing at the algorithmic level from just reading the STL source code because there are too many low-l...