c++

w8004 compiler warning BDS6 c/c++

Hello It is a best practise to initialise a variable at the time of declaration. int TMyClass::GetValue() { int vStatus = OK; // A function returns a value vStatus = DoSomeThingAndReturnErrorCode(); if(!vStatus) //Do something else return(vStatus); } In the debug mode, a statement like this int vSt...

c++ vector<char> and sockets

Is there a way to call send / recv passing in a vector ? What would be a good practice to buffer socket data in c++ ? For ex: read until \r\n or until an upper_bound ( 4096 bytes ) ...

c++ compiling problem

Hi, I'm trying to compile a c++ program, which is something I didn't do for a long time... What I'm trying is: g++ -c A.cpp -o A.o g++ -c dir/B.h -o B.o which seem to work, and then I try: g++ A.o B.o -o A -lX11 -lpthread and get: B.o: file not recognized: File format not recognized collect2: ld returned 1 exit status...

Useful ways to use CppDepend

For a while now I've seen a lot of blog posts about NDepend and how useful it can be, but I've never been able to try it as I don't work in .Net. A couple days ago I saw that a C++ version was released. Finally a version I can try. The features look cool and interesting, but I'm having trouble seeing where it would be useful. I can t...

What is a common C/C++ macro to determine the size of a structure member?

In C/C++, how do I determine the size of the member variable to a structure without needing to define a dummy variable of that structure type? Here's an example of how to do it wrong, but shows the intent: typedef struct myStruct { int x[10]; int y; } myStruct_t; const size_t sizeof_MyStruct_x = sizeof(myStruct_t.x); // error Fo...

getting an error of "Service not found" in a async_resolve handler

I have code that looks like the following: //unrelated code snipped resolver.reset(new tcp::resolver(iosvc)); tcp::resolver::query query(host, port); resolver->async_resolve(query, boost::bind(&TCPTransport::handle_resolve, this, boost::asio::placeholders::error, boost::asio::placeholders::iterator)); LOG4CXX_INFO(logge...

I can't understand this line - dereferencing an address of private member variable or what?!

I asked a question while ago about accessing the underlying container of STL adapters. I got a very helpful answer: template <class T, class S, class C> S& Container(priority_queue<T, S, C>& q) { struct HackedQueue : private priority_queue<T, S, C> { static S& Container(priority_queue<T, S, C>& q) { ...

How does this C++ code compile without an end return statement?

I came across the following code that compiles fine (using Visual Studio 2005): SomeObject SomeClass::getSomeThing() { for each (SomeObject something in someMemberCollection) { if ( something.data == 0 ) { return something; } } // No return statement here } Why does this compile if t...

writing binary data

Hello, I am writing to binary file using fstream and when open the file using binary flag. I needed to write some text as binary, which a simple write did the trick. The problem is that I need also to write (as shown in hexadecimal) 0. The value when opened in binary notepad is shown zero, but when tried to write this the value not zer...

Detouring DrawText

I've downloaded and compiled the Microsoft detouring library. Inside my project I've included the header file and added the .lib file as a dependency. Everything compiles without errors. Now I've been trying to detour DrawText, but for some reason that detoured function doesn't get called at all. Similiarly I tried detouring the Sleep fu...

Why is linker optimization so poor?

Recently, a coworker pointed out to me that compiling everything into a single file created much more efficient code than compiling separate object files - even with link time optimization turned on. In addition, the total compile time for the project went down significantly. Given that one of the primary reasons for using C++ is code ...

Scheduled Task Communication (using ITask interface)?

Is there anyway using the ITask interface to communicate with a scheduled task? I have tasks that users can cancel, pause, etc and a main console that displays information about the tasks. Right now I can only tell if they are running or not via the GetStatus method. What I would like to do is connect to the task and pass a string (poten...

Callback from a C++ dll to a delphi application

Application is written in delphi 2010 and the underlying dll is a C++ dll. In ideal case, when your application is in C++; The dll makes a callback to an application when an event occurs. The callback is implemented through an interface. Application developers implements the abstract c++ class and pass the object to the dll. The dll wi...

kdtree implementation C++

Any recommendations for a C/C++ kd-tree? I'm looking for an existing implementation which the poster hopefully has worked with or has heard good things about. Also, I need to use this kd-tree to do a 1/2-NN search. ...

Static variable accessed from different compilation units potentially problematic?

When I started as at my first job as software developer I was assigned to create a system for that allows writing and reading C++ values (or objects) from and to a PDF document. This required a system for mapping types to an id and vice versa. The codebase was huge and there were several 'layers' of code (basic framework layer, tools-lay...

Removing a node From Doubly Threaded LnkLst

Hello. Im trying to remove a single node from a doubly threaded linked list. What I have works..Its just terribly inefficient. I was wondering if I can get some expert advice or some while termination condition tips. Here is the function in which I remove 1 node from a set of Rating Nodes, stored in headByRating and a set of Name nod...

Acceptable to use virtual inheritance to prevent accidentally creating a diamond?

This is a simplification of some real code, and a real mistake I made when I didn't realize someone else had already implemented Foo and derived from it. #include <iostream> struct Base { virtual ~Base() { } virtual void print() = 0; }; struct OtherBase { virtual ~OtherBase() { } }; struct Foo : public Base { // better to us...

Why is it so slow iterating over a big std::list ?

As title suggests, I had problems with a program of mine where I used a std::list as a stack and also to iterate over all elements of the list. The program was taking way too long when the lists became very big. Does anyone have a good explanation for this? Is it some stack/cache behavior? (Solved the problem by changing the lists to s...

shared_ptr and references in C++

References in C++ are a conveneint construct that allow us to simplify the following C code: f(object *p){ //do something } int main(){ object* p = (object*) calloc(sizeof(object)); f(p); } to f(object& o){ //do something } int main(){ object o = object(); f(o); } Shared pointers are another convenience in C++ that s...

Determine number of non-zero digits right of decimal point

I would like compute the number of non-zero and non-repeating (ie. 1.999999999) to the right of the decimal point. Eg: x.xx = 2 x.xxx = 3 x.xxx000 = 3 I can do this by converting the number to a string but I was wondering if there is a faster way using math. Any ideas? Thanks. EDIT: Many people seem to think this is a fools errand b...