c++

execv, select and read

Hello, I am creating a child-parent fork() to be able to communicate with a shell(/bin/sh) from the parent through a pipe. The problem is: In a parent I set a select() on a child output, but it unblocks only when the process is finished! So when I run say ps it's okay. but when I run /bin/sh it does not output until shell exits. But I ...

Permuting All Possible (0, 1) value arrays

I am having writing an algorithm to generate all possible permutations of an array of this kind: n = length k = number of 1's in array So this means if we have k 1's we will have n-k 0's in the array. For example: n = 5; k = 3; So obviously there are 5 choose 3 possible permutations for this array because n!/(k!(n-k)! 5!/(3!2!) = (5...

Unit separator in C++

How could I include a unit separator (value 31 in ascii table) in a string other than using snprintf()? I want to do like we normally initialize a string. eg char[100] a = "abc" ...

Solving cross referencing

I have a problem creating some form of hierarchy with different object types. I have a class which has a member of another class, like this: class A { public: A(){} ~A(){} void addB(B* dep){ child = dep; dep->addOwner(this); } void updateChild(){ child->printOwner(); } void print(){ ...

How to add a C++ compiler flag to extconf.rb

I'm writing a Ruby extension, for which I have a standard mkmf configuration script, but I need to add a special include flag (--std=c++0x) to all of the C++ compilation steps. I don't want it in the C compilation steps, 'cause it throws warnings. How should I do this? require 'mkmf' create_makefile('thing') For instance, I tried $CXX...

operator as template parameter

Is it possible? template<operator Op> int Calc(int a, b) { return a Op b; } int main() { cout << Calc<+>(5,3); } If not, is way to achieve this without ifs and switches? ...

Undefined reference to operator new

I'm trying to build a simple unit test executable, using cpputest. I've built the cpputest framework into a static library, and am now trying to link that into an executable. However, I'm tied into a fairly complicated Makefile setup, because of the related code. This is my command line: /usr/bin/qcc -V4.2.4,gcc_ntoarmle_acpp-ne -lang...

C++ stack variables and heap variables

When you create a new object in C++ that lives on the stack, (the way I've mostly seen it) you do this: CDPlayer player; When you create an object on the heap you call new: CDPlayer* player = new CDPlayer(); But when you do this: CDPlayer player=CDPlayer(); it creates a stack based object, but whats the difference between that a...

Which applications are best developed in C++ over C# in today's business?

I'm only curious. I have already developed microcontroller software in C and Assembly. So, I can see an application for these languages. As for today, I'm specialized in information and process systems and even though C++ is object-oriented and offers powerful development capabilities, we mostly develop in .NET C#. So my question is t...

Destruction of objects with static storage duration

Consider the following program. struct s { ~s(); }; void f() { static s a; } struct t { ~t() { f(); } }; int main() { static s b; static t c; } I'm trying to figure out what exactly the standard guarantees with respect to the destruction of static objects, but I'm finding the text of C++03[basic.start.term] rather insuffi...

how to declare a template class as a friend in c++

Hello all, I wana know if we can make a partial specialized class as a friend class. template< class A, class B > class AB{}; class C; template < class B > class AB< C, B >{}; class D{ template< class E > friend class AB< D, E >; } How to achieve the above. ...

accessing an array

i am declaring a global array,and then assigning the values inside a if statement. But when i am using the array in another if statement the array has different values other than i assigned previously. For example: int arr[5]; xyz(bool p,bool q) { if(p) { for(int i=0;i<5;i++) { arr[i]=rand()%100; ...

Why use FitNesse when the tests are highly technical?

It seems to me FitNesse has the following advantages: Let a non-technical person define sets of test data and expected results (how they define success). A non-technical person could be a user, a product manager, or possibly a software quality professional who does not have access to the source code and/or does not know how to program ...

Reading custom format files in C#

I would like to fetch n bytes from specific place in a file into my specific data structure (a struct). The old C - application (which we are porting) uses fseek() and fread(). Is where a comparable solution in C#/.Net, without using the Win32-API? ...

Assigning and Conditional Testing Simultaneously in C++

I have three functions that return integer error codes, e.g. int my_function_1(const int my_int_param); int my_function_2(const int my_int_param); int my_function_3(const int my_int_param); I want to assign and test for error at the same time for brevity. Will the following work and be portable? int error=0; ... if ( error || (...

C++ Virtual Destructor Crash

I have the following class hierarchy: class Base { public: virtual ~Base(); }; class Derived : public Base { public: virtual ~Derived(); }; class MoreDerived : public Derived { public: virtual ~MoreDerived(); }; along with an objects Base* base = new Base(); MoreDerived* obj = new MoreDer...

Setprecision() for a float number in C++?

In C++, What are the random digits that are displayed after giving setprecision() for a floating point number? Note: After setting the fixed flag. example: float f1=3.14; cout < < fixed<<setprecision(10)<<f1<<endl; we get random numbers for the remaining 7 digits? But it is not the same case in double. ...

Why do static libraries end in '.a' c++/c ?

Just doing a little work this morning making some static libraries and wanted to know why static libraries end with '.a'. No one in my office knew so I thought I would ask around on SO. We are writing code in C++/C/Obj-C ...

How best to store VERY large 2D list of floats in c++? Error-handling?

I'm migrating some code from c to c++. I've changed some malloc calls for structure memory allocation to new calls. Basically before the code I'm porting was malloc'ing arrays that contain multiple sets of frame coords, each a couple hundred thousand floats in length -- so the total array length could be in the tens of millions of co...

NUMA memory regions allocation in Windows 7

Our application is: Hardware configuration is a dual Xeon server running Windows 7/64bit. Each Xeon has it's own 12gb RAM in a [NUMA][1] configuration with a bridge connecting two memory regions together. All software is written using VS2008 in c++ and compiled as 64 bit applications. A Generation app creates a large shared memory...