c++

#ifdef for 32-bit platform

In an application I maintain, we've encountered a problem with file descriptor limitations affecting the stdlib. This problem only affects the 32-bit version of the standard lib. I have devised a fix for my code and would like to implement it, but only when compiling for 32-bit executable. What pre-processor symbol can I #ifdef for to d...

C/C++ pattern to USE_HEAP or USE_STACK

Is there a way to define a macro (or something similar) that would allow objects to be allocated on the stack or on the heap, cleanly? eg. Current code: A a; a.someFunc(); The simplest suggestion might be the following, but as you can see below, it's not very clean to maintain 2 sets of code. #ifdef USE_STACK A a; a.someFunc();...

Iterating a read() from a socket

Is this the proper way to iterate over a read on a socket? I am having a hard time getting this to work properly. data.size is an unsigned int that is populated from the socket as well. It is correct. data.data is an unsigned char *. if ( data.size > 0 ) { data.data = (unsigned char*)malloc(data.size); memset(&data.data, 0, data...

Handle "new top level window" events in Xlib/Xt

So I'm in a situation where I need to know when a top level window gets created. I'm working at the Xlib/Xt level and on a Window Manager that doesn't support the EWMH specification. My idea is to hook into the root window's SubstructureNotify events. But things are not as simple as just that. The problem is that not every CreateNotify...

How do you convert a string to ascii to binary in C#?

A while back (freshman year of high school) I asked a really good C++ programmer who was a junior to make a simple application to convert a string to binary. He gave me the following code sample: void ToBinary(char* str) { char* tempstr; int k = 0; tempstr = new char[90]; while (str[k] != '\0') { itoa((int)str...

class & function names highlighting in Vim

I just recently set up my Vim environment from Textmate, after becoming addicted to its modal input. However, syntax highlighting seems to be not so beautiful in Vim. I code in C++ and since the function call and class names can't be highlighted, the code is more difficult to read. I played with color scheme for a bit, but couldn't fin...

CoInitializeEx fails when calling OpenCV method cvLoadImage()

Hello, I am trying to integrate some OpenCV functionality into my application. Currently I have code set up with DirectShow to get a video feed from my camera, which is then showed in an MFC window. This code cannot be changed or removed. The code runs completely fine, but regardless of the location i place the following line of code...

How do I deal with "Project Files" in my Qt application?

My Qt application should be able to create/open/save a single "Project" at once. What is the painless way to store project's settings in a file? Should it be XML or something less horrible? Of course data to be stored in a file is a subject to change over time. What I need is something like QSettings but bounded to a project in my appl...

C++ polymorphism not supported for pointer-to-pointer

I'm searching for a proper way to clean my pointers. Here the example code: class Parent { protected: int m_Var; public: Parent() : m_Var(0) {} virtual ~Parent() {} void PubFunc(); }; class Child : public Parent { protected: bool m_Bool; public: Child() : m_Bool(false) {} virtual ~C...

A simple cobol program needs to be recoded as a C++ program to read environment variables passed by wrapping security software

I have a COBOL exe program which calls a COBOL dll which in turn calls a COBOL program using a dos interrupt 'x91 - the calling program uses an 'x91' to activate an EXE file as if it were typed in as an operating system command line entry. The security program which wraps my cobol code is a third party program which wraps around my pr...

pthread returns 251

pthread_create returns the value 251 without creating the thread. Does anyone know what the problem is? Please help. The machine is a HP-UX. I'm new to multi-threading. #include <stdio.h> #include <stdlib.h> #include <pthread.h> void *print_message_function( void *ptr ); main() { pthread_t thread1, threa...

Converting from Derived* to Base*&

I was trying to answer the question mentioned here by passing the reference to the pointer instead of pointer to pointer like this: class Parent { }; class Child : public Parent { }; void RemoveObj(Parent*& pObj) { delete pObj; pObj = NULL; } int main() { Parent* pPObj = new Parent; Child* pCObj = new Child; pP...

C/C++: Array size at run time w/o dynamic allocation is allowed?

I've been using C++ for a few years, and today I don't know if this is a mere brainfart or what, but how can this be perfectly legal: int main(int argc, char **argv) { size_t size; cin >> size; int array[size]; for(size_t i = 0; i < size; i++) { array[i] = i; cout << i << endl; } return 0; } ...

Code convert from C++ to C

Hello, I have a Code which is C++ (*.cpp - source, *.hpp - header files). In the overall code,there are many classes defined, their member functions, constructors, destructors for those classes, few template classes and lots of C++ stuff. Now i need to convert the source to plain C code. I have following questions - 1.) Is there an...

Apache server (C++) is not starting in fips mode?

Hi Could any one know apache server is not starting in fips mode in some PCs. Description: We have a client-server application where Apache webserver is the server and IE is the browser. Recently we have made this Apache webserver FIPS 140-2 compliant. Hence now it can work in FIPS mode. We are able to run the server in FIPS mode on a...

Are get and set functions popular with C++ programmers?

I'm from the world of C# originally, and I'm learning C++. I've been wondering about get and set functions in C++. In C# usage of these are quite popular, and tools like Visual Studio promote usage by making them very easy and quick to implement. However, this doesn't seem to be the case in the C++ world. Here's the C# 2.0 code: public...

Dynamic Binding in C++

I need some clarification on dynamic binding in C++ .I'm confused about the following: In C you can have an array of function pointers & assign different functions of the same signature & call them based on the index; is this Dynamic binding? In C++ you can have an array of base class pointers but you can call different functions of th...

Must I use pointers for my C++ class fields?

After reading a question on the difference between pointers and references, I decided that I'd like to use references instead of pointers for my class fields. However it seems that this is not possible, because they cannot be declared uninitialized (right?). In the particular scenario I'm working on right now, I don't want to use normal...

What are the reasons for preferring Singleton or function scope local static objects over one another?

Both Marshall Clines' "C++ FAQ Lite" and Scott Meyers' Effective C++ suggest using functions returning local static objects to avoid possible problems with non-local static object initialization order. In short (from "Effective C++", 3rd edition by Scott Meyers): FileSystem& tfs() { static FileSystem fs; return fs; } Both writers...

What's the best technique for exiting from a constructor on an error condition in C++

What's the best technique for exiting from a constructor on an error condition in C++? In particular, this is an error opening a file. Thanks for the responses. I'm throwing an exception. Here's the code (don't know if it's the best way to do it, but it's simple) // Test to see if file is now open; die otherwise if ( !file.is_open() )...