c++

static local variable and static local object initialization

In VC++2008 there is a serious difference in initialization of static local variable and static local object. Static local variable is initialized before main() and its definition statement within the function is skipped. Static local object is initialized by 0 value before main() and its definition statement within the funct...

C++ Exposed property for COM in idl is showing as lower case "all of a sudden"

I have this old C++ COM component. I took the latest code base, built it and found that one of the properties has become lower case. For example, in the pre-compiled dll i have a property "Type", but when building from source it's called "type". The idl shows that the property is called "Type". So what could possibly be happening her...

[Qt/C++] Functions cannot access objects defined in the same class .. ! Possibly a bug ?

Hey guys .. Well ever since I've started programming in Qt, I've been having problems regarding scope visibility of objects I've defined .. Till now I've managed to find ways to get around these things but now its getting annoying .. For example, I have this class defined called Canvas: class Canvas : public QWidget//, public MainWindo...

Is there anything that prevents this form of use of XOR test?

Is there anything that prevents this form of use of XOR test? bool result = false; bool b1 = false; bool b2 = false; ... if ( b1 ^ b2 ) { result = true; } ...

How do I get the coordinates of some text thats part of an image?

I want to cut up the image based on various text markers placed around within it. The font/size of the marker is up to me. I know commercial OCR packages provide this in their APIs but I'm hoping I can code this up myself. Ideally I wouldn't have to go pixel to pixel and compare against an image of the marker text. I'm good with C++/...

Goto out of a block: do destructors get called ?

Consider the following code: void foo() { { CSomeClass bar; // Some code here... goto label; // and here... } label: // and here... } Will the destructor of bar be called ? ...

What is the experience when moving to VS10?

We're thinking of upgrading a very large product to VS10. I've heard a lot of good things about VS10 and am very excited about the new C++0x features however when playing around with VS10 I had one case in which a sample toy application crashed (which it didn't in VS8) and one case in which there seems to be a compiler bug in some C++0x...

On Sandboxing a memory-leaky 3rd-Party DLL

I am looking for a way to cure at least the symptoms of a leaky DLL i have to use. While the library (OpenCascade) claims to provides a memory manager, i have as of yet being unable to make it release any memory it allocated. I would at least wish to put the calls to this module in a 'sandbox', in order to keep my application from not l...

Correct way of checking if threads are done?

I'm using multithreading in my application with _beginthread and right now to wait until all threads are done I have global bools that get set to true as each thread completes so I'm in a while loop until then. There must be a cleaner way of doing this? Thanks ...

Why are C++ STL iostreams not "exception friendly"?

I'm used to the Delphi VCL Framework, where TStreams throw exceptions on errors (e.g file not found, disk full). I'm porting some code to use C++ STL instead, and have been caught out by iostreams NOT throwing exceptions by default, but setting badbit/failbit flags instead. Two questions... a: Why is this - It seems an odd design decis...

"The specified module could not be found" error when running C# ASP.NET web service referring C++ dll

I have C# ASP.NET web service project in visual studio 2005 which refers a C++ dll. But when I try to run the web service I get the following error which is shown in the web browser: The specified module could not be found. (Exception from HRESULT: 0x8007007E) Description: An unhandled exception occurred during the execution of the cu...

C++ main only uses ~20% time says gprof

I tried profiling my C++ program with gprof. The program itself ran for about 53 seconds, so I dont understand why it says, main only ran for about 8.29 seconds. Any explanation on this? Here is an excerpt: index % time self children called name <spontaneous> [2] 20.5 0...

how to organize test cases with boost::test library?

I have a project of 50+ .H/.CPP files/classes. I would like to test every class with its own test case, which will include methods for testing of different aspects of every class. My classes are located in different directories, like this: /project /include /SuperModule Foo.h Foo.cpp .. Alpha.h Alpha.cpp ...

Convert datetime from one timezone to another (native C++)

Customers from around the world can send certain 'requests' to my server application. All these customers are located in many different time zones. For every request, I need to map the request to an internal C++ class instance. Every class instance has some information about its 'location', which is also indicated by a time zone. Eve...

Join MSB and LSB of a 16 bit signed integer (two's complement)

I'm working with a proprietary protocol that transmits integers as 16 bit two's complement in two parts. The LSB is transmitted first followed by the MSB. Is the following code to restore the original value correct? unsigned char message[BLK_SIZE]; // read LSB to message[0] and MSB to message[1] short my_int = (message[1] << 8) | messag...

finding the default ccsid on a z/OS system using C++ routines

Hello, We are attempting to get the native CCSID (char encoding) on a z/OS system? Is there a way to retrieve the native CCSID on z-series system using XL C/C++ runtime routines or any other C/C++ routine? Please let me know. Thanks! - Azeem ...

std::string vs string literal for functions

I was wondering, I normally use std::string for my code, but when you are passing a string in a parameter for a simply comparison, is it better to just use a literal? Consider this function: bool Message::hasTag(string tag) { for(Uint tagIndex = 0; tagIndex < m_tags.size();tagIndex++) { if(m_tags[tagIndex] == tag) ...

gcc's fvisibility at compile time or link time

I am trying to limit the ABI of a shared library using the gcc's fvisibility feature. However I am confused what is the correct way to do it. My makefile organizes the build process in two stages. At the first step all .cpp files are built to object files using some gcc options. Then all the object files are linked together using anoth...

Dynamic memory and constructor exceptions

Early today I discovered function try-catch blocks (from here in fact) and then went on a bit of a research spree - apparently they're main use is it catch exceptions throw in by a constructor initialiser list. Anyway, this sent me thinking about failing constructors and I've got to a stage where I just need a little clarification. This...

file reading: feof() for binary files

Hey; I am reading a binary file. and when it reaches the end. it seems it is terminated by feof() function. is it because there is no EOF character for binary files? if so how can i solve it. currently my code is using a while loop while (!feof(f)) when it reaches the end of file at position 5526900. it doesn't stop. it just keeps...