c++

ASM-optimizations lost after compilation?

Not that I'm in that situation currently, but I'm just interested in the answer... Assuming you have some code written in C/C++ and you want to manually optimize it by modifying it in ASM. What happens if you alter the code in C/C++ and recompile from source. Sure, the optimization on the just compiled file is lost. How do you avoid th...

Compute Arithmetic Sum to Communicate with Machine Over Serial

I am communicating with a machine over serial. Part of the protocol communication spec states that the control sum is an "arithmetic sum of bytes from <'PS'> (included), <'data'> to <'CS'>" The packet messages are structured as follows: <'PS'><'data'><'CS'>, where: <'PS'> - Packet Size Length: 1 Value: 0x02 to 0x63 Max packet leng...

C++ undeclared identifier - object from .net dll class

I have a vb.net dll which I imported in an unmanaged c++ project. I successfully created an object of the class object using: CComPtr< IWSconnection > pIWSconnection; pIWSconnection.CoCreateInstance( __uuidof(IWSconnection ) ); Then, when I tried to call a method from the dll: pIWSconnection.connect(...); I am getting an erro...

Using vb.net dll in c++ - class is abstract

I created a vb.net dll which I am using in an unmanaged c++ project. When I try to create an object of the class, I am getting an error: cannot instantiate abstract class Why would my class be abstract? How can I modify it so that it won't be abstract? ...

Free / Open Source Windows Fortran Compiler Compatable with Visual Studio

I'm trying to link in some legacy Fortran code with a Visual Studio C++ project. I tried using the Windows build of gfortran to build my static library but Visual Studio complains about unresolved external symbols. I guessing this is because mixing mingw and visual studio compilers is a horrible, horrible idea. I've googled a bit an...

Declare class member to have internal linkage

Basically I have code which looks like this inside a header file: class Bar; class Foo { public: Bar GetBar(); }; class Bar { Foo CreateFoo() {} }; Bar Foo::GetBar() {...} The problem with this code is that as soon as the header is included in more then one file the linker will complain that there are multiple definitions of ...

OOLua link errors

Code #include <OOLua/oolua.h> class foo { public: int bar(); }; OOLUA_CLASS_NO_BASES(foo)//class has no bases OOLUA_NO_TYPEDEFS OOLUA_MEM_FUNC_0(int,bar) OOLUA_CLASS_END void test() { OOLUA::Script s; s.register_class<foo>(); } Compiler output 1>main.obj : error LNK2001: unresolved external symbol "public: static...

Tips for joining engine and GUI

I have a game playing engine written in C++. I have my own "development" GUI. The program is for sale in Japan and I have a Japanese publisher that has written an commercial GUI to join up with my game playing engine. We have had this arrangement for many years. Both my engine and his GUI are large, complex and undergo regular changes be...

issues with porting a DLL C++ class library to Visual Studio

Hi there. I wrote a class library in C++ and successfully compiled it in Linux with g++ as a shared object, then created a few apps that use it. Now I have to port it to VS2008. I gave all the classes the required __declspec(dllexport) prefixes, then tried to compile it. I get a pile of warnings, which basically have to do with: my cu...

Mpi usage problem

I installed mpi into windows. I can use its libraries. The problem is that in windows when i write mpiexec -n 4 proj.exe into command prompt it does not make the proper operations. 4 different processes uses the whole code file seperately. They dont behave like parallel processes that are working only in the MPI_Init and MPI_Finalize row...

How do you populate an x86 XMM register with 4 identical floats from another XMM register entry?

I'm trying to implement some inline assembler (in C/C++ code) to take advantage of SSE. I'd like to copy and duplicate values (from an XMM register, or from memory) to another XMM register. For example, suppose I have some values {1, 2, 3, 4} in memory. I'd like to copy these values such that xmm1 is populated with {1, 1, 1, 1}, xmm2 wit...

why using directive in C++ is not encouraged?

Hi I read that using directive is not encouraged in C++ saying never put using directives in header files. Why is it like that? Any hint for me? Thanks! ...

Create C++ Code from Visio UML diagram

Visio 2010 Beta can generate static UML diagram from Native C++ project, and it's great. How is it possible to solve reverse problem: given a static UML diagram from Visio, generate header files? Or, maybe, there are free tools for architecture development and reverse engineering? EDIT Generally speaking, I don't need diagrams to be st...

How can I return a random line from a file? Interview Question

I am preparing for a phone interview. I came upon these questions on the internet. Can anyone tell me some good answers for these? Suppose I give you a text file and ask you a to write a program that will return a random line from the file (all lines must have equal probability to be returned) Same as part 1, except this time the enti...

why does the derived class inherit the private members of the base class?

I know that the derived class can't access the private members of the base class, so why does the derived class inherit the private members of the base class? Is there any case that it is useful? Thanks! ...

double precision C++

I think the precision of double is causing that problem, as it was described in similiar posts, but I would like to know if there is a way to achieve correct result. I'm using function template which compares two parameters and returns true if they are equal. template <class T> bool eq(T one, T two) { if (one == two) return true; ...

Does calling the constructor of an empty class actually use any memory?

Suppose I have a class like class Empty{ Empty(int a){ cout << a; } } And then I invoke it using int main(){ Empty(2); return 0; } Will this cause any memory to be allocated on the stack for the creation of an "Empty" object? Obviously, the arguments need to be pushed onto the stack, but I don't want to incur any extra ...

C++ Exception Handling In Critical Section (pthreads)

[Edit: (copied from a comment) As it turns out, the problem was elsewhere, but thank you all for your input.] I have a shared container class which uses a single mutex to lock the push() and pop() functions, since I don't want to simultaneously modify the head and tail. Here's the code: int Queue::push( WorkUnit unit ) { pthread_mu...

What is the popular JSON c++ library?

HI, Can someone please suggest what is the popular JSON c++ library? I find a list here http://www.json.org/, but I don't know which one is popular? Thank you. ...

why are concrete types rarely useful as bases for further derivation

Hi, I read "Concrete types are rarely useful as bases for further derivation"------------ Stroustrup p. 768 How to interpret this? Does it mean that we should get derived class from the base class with pure virtual function? However, I see a lot of code with derived class derived from concrete types. Can anyone help me out? ...