c++

How does c++ by-ref argument passing is compiled in assembly?

In the late years of college, I had a course on Compilers. We created a compiler for a subset of C. I have always wondered how a pass-by-ref function call is compiled into assembly in C++. For what I remember, a pass-by-val function call follows the following procedure: Store the address of the PP Push the arguments onto the stack Per...

C++ Function Pointer issue

For some reason trying to pass a pointer to this function to a varadic function produces the following error: 1>c:\... : error C2664: 'PyArg_ParseTuple' : cannot convert parameter 3 from 'int (__cdecl *)(PyObject *,void *)' to '...' 1> Context does not allow for disambiguation of overloaded function PyArg_ParseTuple(args, "O&O&:...

Efficient coding help

I am currently writing code in C++ to find all possible permutations of 6 integers and store the best permutation (i.e. the one whose total is closest to a given value). I am trying to write this code as efficiently as possible and would apreciate any advice or examples. I was considering storing the integers in an array and performing...

What does floating point error -1.#J mean?

Recently, sometimes (rarely) when we export data from our application, the export log contains float values that look like "-1.#J". I haven't been able to reproduce it so I don't know what the float looks like in binary, or how Visual Studio displays it. I tried looking at the source code for printf, but didn't find anything (not 100% s...

How can I see the Assembly code for a C++ Program ?

How can I see the Assembly code for a C++ Program ? What are the popular tools to do this ? ...

Given a pointer to a C++ object, what is the preferred way to call a static member function?

Say I have: class A { public: static void DoStuff(); // ... more methods here ... }; And later on I have a function that wants to call DoStuff: B::SomeFunction(A* a_ptr) { Is it better to say: a_ptr->DoStuff(); } Or is the following better even though I have an instance pointer: A::DoStuff() } This is purely ...

How does code written in one language get called from another language

This is a question that I've always wanted to know the answer, but never really asked. How does code written by one language, particularly an interpreted language, get called by code written by a compiled language. For example, say I'm writing a game in C++ and I outsource some of the AI behavior to be written in Scheme. How does the c...

How can I compute the dense disparity map from to stereo images ?

How can I compute the dense disparity map from to stereo images ? My idea so far was to go over all the pixels from the first image, and scan the second image for matches. To compare the similarity of two pixels i computed the squared difference of pixels in a small window around them. The algorithm works relatively well on synthetic i...

What does it mean when "virtual" is in "class Foo : public virtual Bar" as opposed to "virtual void frob()"?

What does it mean when "virtual" is in "class Foo : public virtual Bar" as opposed to "virtual void frob()"? For a given method there are 8 cases stemming from the presence or absence of virtual in the following three locations. A superclass's functions. The inheritance chain for this class. This classes functions. I think I underst...

Large buffers vs Large static buffers, is there an advantage?

Hello, Consider the following code. Is DoSomething1() faster then DoSomething2() in a 1000 consecutive executions? I would assume that if I where to call DoSomething1() it 1000 times it would be faster then calling DoSomething2() it 1000 times. Is there any disadvantage to making all my large buffers static? #define MAX_BUFFER_LENGTH...

Best C++ Code Formatter/Beautifier

There are lots of source-code formatting tools out there. Which ones work best for C++? I'm interested in command-line tools or other things that can be automatically run when checking code in/out, preferably without needing to launch an editor or IDE. (If you see the one you like already listed as an answer, vote it up. If it's not ...

How do you manually insert options into boost.Program_options?

I have an application that uses Boost.Program_options to store and manage its configuration options. We are currently moving away from configuration files and using database loaded configuration instead. I've written an API that reads configuration options from the database by hostname and instance name. (cool!) However, as far as I...

C++ Reading Files

What is the minimum code required to read a file and assign its contents to a string in c++? I did read a lot of tutorials that worked but they were all different in a way so i am trying to see why, so if you could please include some explanatory comments that would be great. Related: http://stackoverflow.com/questions/116038/what-is-...

wxwidgets // g++ Compiler error: no matching function for call to 'operator new(..'

Hello, at the moment I try to port a Visual C++ application to Linux. The code compiles without errors in Visual Studio, but I get many compiler errors under Linux. One of these errors is: ../src/wktools4.cpp:29: error: no matching function for call to 'operator new(unsigned int, const char [40], int)' More information: ...

Use NMAKE to make all source in a directory?

Using nmake, is it possible to have the makefile build all the .cpp files in the current directory automatically, without having to specify them individually? So, instead of something like: O = $(OBJ_DIR)/main.obj {$(SOURCE_DIR)}.cpp{$(OBJ_DIR)}.obj: ---COMPILE $< HERE--- I'd like to avoid having to specify each obj to make. Can...

C++ constructor problem

#include <iostream> using namespace std; // This first class contains a vector and a scalar representing the size of the vector. typedef class Structure1 { int N; double* vec; public: // Constructor and copy constructor: Structure1(int Nin); Structure1(const Structure1& structurein); // Accessor functions: int get_N() { return N...

C++: Trying to import class as a class member into another class, does not copy properly.

Thanks to all that responded to my previous thread. There is still a problem with this simple program that I would like to solve. I am trying to import one class into another as a member object. The output of this program is confusing, though. As a test of the code, I output the scalar contained within the first class object. This w...

Programmatically Add/Remove tabs on wxNotebook by PageText

I need to be able to programmatically add and remove tabs on a wxNotebook by the text/label that is displayed on each tab. In windows, using a tab control and tab pages, I would be able to reference each tab by a key. The tab control has a map of tab pages keyed on the text of each tab. I'm trying to write some helper methods to recreat...

Some useful site with examples C++ and Java?

Could someone post some good links with examples of programs with code in C++ and(or) Java? ...

How can I disambiguate this template code?

I'm having trouble figuring out how to solve a compiler error I'm running into. I've reduced it down to this simplest-case representation: enum EAtomId { EAtomId_Test }; int StringFormat(char* o_dest, size_t i_destSizeChars, const char* i_format, ...); template <size_t SIZE> int StringFormat(char (&o_dest)[SIZE], EAtomId i_format, ......