c++

Is extern "C" only required on the function declaration?

I wrote a C++ function that I need to call from a C program. To make it callable from C, I specified extern "C" on the function declaration. I then compiled the C++ code, but the compiler (Dignus Systems/C++) generated a mangled name for the function. So, it apparently did not honor the extern "C". To resolve this, I added extern "...

Error calling function and passing a reference-to-pointer with a derived type

Can somebody explain why the following code is not valid? Is it because the offset for the variable named d is different than the variable named b? class Base { public: int foo; }; class Derived : public Base { public: int bar; }; int DoSomething( Base*& b ) { return b->foo; } Base* b = new Derived; Derived* d = new Derived; int mai...

Why is MapX so slow?

I'm using the MapX 5.0 ActiveX plugin in an MFC application. I've got some temporary layers that I create in the following way: // Create a new Fields Object CMapXFields fields; fields.CreateDispatch(fields.GetClsid()); // Create the field definitions for the new layer. // Storing 64bit integers here. Is this even possible, btw? fields...

null pointer when getting function pointer using boost::function::target

After reading this answer I thought I had a solution. At least the answer there is what I would like to do but I'm having a problem with the implementation. here is an outline of what I am trying to do typedef map<string, double*> myMap; typedef int (*ftwpt)(const char*, const struct stat*, int); typedef boost::function<int(const char...

Parrallel reads from STL containers

It is safe to read a STL container from multiple parallel threads. However, the performance is terrible. Why? I create a small object that stores some data in a multiset. This makes the constructors fairly expensive ( about 5 usecs on my machine. ) I store hundreds of thousands of the small objects in a large multiset. Processing t...

Serialize a C# class to binary be used by C++. How to handle alignment?

I am currently serializing a C# class into a binary stream using BinaryWriter. I take each element of the class and write it out using BinaryWriter. This worked fine as the C++ application reading this binary file supported packed structs and hence the binary file could be loaded directly. Now I have got a request to handle alignment ...

Problem with overriding "operator<<" in class derived from "ostream"

Hi! I want to make a class based on "ostream" that does some auto-formatting to generate comma- or tab-separated-value files. My idea was to override "operator<<" to have it insert a separator before each value (except at the beginning and end of a line), and also to quote strings before writing them. Within the overriding "operator<<" ...

Get a pointer to structure in a map C++

Ok so I have struct like this typedef struct { float x; float y; char name[]; } pTip; And another struc typdef struct { float xx; float yy; pTip *tip; }finalTip; I create and populate a map<string, pTip> maps That works fine. I am now trying to generate vector of finalTips I do: map<string, pTip>::const_iterator it...

How Do I use LoadLibrary in COM Accross Multiple Threads?

Let's say that I have the following code that's run in one thread of a multi-threaded COM application: // Thread 1 struct foo { int (*DoSomething)(void ** parm); }; HMODULE fooHandle = LoadLibrary("pathToFoo"); typedef int (*loadUpFooFP)(foo ** fooPtrPtr); loadUpFooFP loadUpFoo; loadUpFoo = (loadUpFooFP)GetProcAddress(fooHandle, "f...

c++ derived class with no variables

I have a derived class which has no variables but simply adapts the interface to another class - is there a special name for such a class in C++? ...

Good multithreading guides?

I'm looking for a good guide/tutorial on multithreading in C++ (and ideally in general). Can anyone point me to a good online resource? EDIT: I intend to familiarize myself with either the boost threading library or the one from Poco. ...

function calling convention with boost::function_types

Hey there, I've just been experimenting with the boost::function_types library recently, and I've come across a bit of a snag. I want to find out the calling convention of a given function, however I'm not quite sure how to do this. Here's what I have so far: This produces an error about how it cannot find the *_cc tag values inside e...

SetJmp/LongJmp: Why is this throwing a segfault?

Hi, The following code summarizes the problem I have at the moment. My current execution flow is as follows and a I'm running in GCC 4.3. jmp_buf a_buf; jmp_buf b_buf; void b_helper() { printf("entering b_helper"); if(setjmp(b_buf) == 0) { printf("longjmping to a_buf"); longjmp(a_buf, 1); } printf("return...

Taking iterators two at a time?

I'll often represent and process polylines like so: typedef std::vector< Point_t > Polyline_t; double PolylineLength(const Polyline_t& line) { double len = 0.0; for( size_t i = 0; i < line.size()-1; ++i ) len += (line[i+1]-line[i+0]).length(); return len; } The most straightforward conversion to bidirectional iter...

What is the C equivalent for reinterpret_cast

Hi What is the C equivalent for reinterpret_cast? Thanks ...

Should I be worried about g++ warnings saying 'inlining failed'?

In a project I'm working on at the office, when we compile a release build (with -Os) we get hundreds of warnings from g++ saying that inlining has failed. Most of these warnings seem to come from boost, however some come from our own library headers (binary .dylibs that we're linking to). Can these warnings generally be safely ignored...

Sorting a Doubly Linked List C++ Question

Trying to do it through a loop that traverses through the list. In the loop im feeding the head node into a sorting function that I have defined and then im using strcmp to find out if which name in the node should come first. Its not working because writing the names too early. Im comparing them all linearly by going down the list ...

binding lvalue to a reference

Hello everyone, I think I am missing smth back in my theoretical background on this thing. I know there were similar posts but I still do not get it. I have such a code: void somefunc1(Word &Key) { somefunc2(Key); } void somefunc2(char &char1) { return; } compiler generates me an error here: somefunc2(Key); [BCC32 Error]...

My 'cout' isn't giving correct value - why?

Simple "sum of digits" code. Compiles but when executed, the last cout gives a "0" for the num int rather than the actual user-input number. Feel free to c&p into your own compiler, if you're so inclined, to see what I mean. How can I get this to output the correct "num" value? Thank you! ~~~ #include <iostream> using namespace st...

Calling C++ (not C) from Common Lisp?

Hello, I am wondering if there is some way to call C++ code from Common Lisp (preferably portably, and if not, preferably in SBCL, and if not, well, then Clozure, CLisp or ECL). The C++ would be called inside loops for numeric computation, so it would be nice if calls were fast. CFFI seems to not support this: "The concept can be ...