c++

Compilers and negative numbers representations

Recently I was confused by this question. Maybe because I didn't read language specifications (it's my fault, I know). C99 standard doesn't say which negative numbers representation should be used by compiler. I always thought that the only right way to store negative numbers is two's complement (in most cases). So here's my question: ...

C++ multiple declaration of function error when linking

Hi, I seem to be forgetting my C++ ... I'm trying to declare some functions in C in separate sources, and including the appropriate .h when necessary. It compiles OK; but the problem is during linking, where the linker complains about functions already being defined. I even tried defining the functions as extern, in a (vain) attempt ...

How to underline individual items in a CListCtrl

We want some items in a CListView to appear like hypertext links. I can make everything underlined by setting the lfUnderline flag in LOGFONT, and creating a font from this, before calling SetFont - but this applies to the whole CListView. Does anyone know how to make individual items in a CListView to appear underlined? ...

How to pass parameters to a Thread object?

I'm working with a C++ class-library that provides a Thread base-class where the user has to implement a run() method. Is there a recommended way on how to pass parameters to that run() method? Right now I prefer to pass them via the constructor (as pointers). ...

SQLite disk usage

SQLite has a reputation of being small, fast and flexible. I used it in one of my C++ projects to save simple statistics to a file. Once for 15 minutes 3-5 new simple records (5 rows of integers) were saved into the database. During few weeks of such SQLite usage I quickly observed clearly noticeable disk usage. I wasn't expecting that, ...

OO design - propagating attributes

Hi, I'm an experienced C programmer dipping my toes in OO design (specifically C++). I have a particular piece of code I hate and would like to clean up using C++. The code implements a display tree for use in a 3d graphics app. It is a linked list of entries which have a type field specifying whether the entry is a window, geometry fea...

How do I compile a .cpp source file into a .dll?

How do I compile a .cpp source file into a .dll? ...

Why does Microsoft's C compiler want the variables at the beginning of the function?

I am currently writing a C (not C++). It seems the Microsoft's C compiler requires all variables to be declared on top of the function. For example, the following code will not pass compilation: int foo(int x) { assert(x != 0); int y = 2 * x; return y; } The compiler reports an error at the third line, saying error C214...

C#: Blowfish Encipher a single dword

Hello, I'm translating a C++ TCP Client into C#.The client is used to encode 4 bytes of an array using blowfish. C++ Blowfish C# Blowfish(C# NET) C++ BYTE response[6] = { 0x00, 0x80, 0x01, 0x61, 0xF8, 0x17 }; // Encrypt the last 4 bytes of the packet only(0x01,0x061,0xF8,0x17) blowfish.Encode(responce + 2, responce + 2, ...

How can I properly parse my file? (Using break/continue)

I have the following data that looks like this for example: 34 foo 34 bar 34 qux 62 foo1 62 qux 78 qux These are sorted based on the first column. What I want to do is to process lines that starts with 34, but I also want the file iteration to quit after it finds no more 34s, without having have to scan through whole f...

How to convert/call a c++ project to/from .Net?

Hi, I currently have a huge project that I've recently converted from VC6 to 2005. Now I'd really like to create a new frontend for some of the functionality, However the main logic of the program is based in c++. Also the code base revolves around it's own metatypes and bespoke classes. The best solution I can come up with is to call ...

C++: How to get the address of an overloaded member function?

Hi, I'm trying to get a pointer to a specific version of an overloaded member function. Here's the example: class C { bool f(int) { ... } bool f(double) { ... } bool example() { // I want to get the "double" version. typedef bool (C::*MemberFunctionType)(double); MemberFunctionType pointer = &C::f; // <- Visual C...

C++ socket server on Mac. Help!

Hey everyone. I'm planning on writing a socket server in C++ running on a Mac. I've been searching through a great portion of the internet without any results. Anyone knows where to start? Or even got a basic source code? Much appreciated. ...

Are uninitialized struct members always set to zero?

Consider a C struct: struct T { int x; int y; }; When this is partially initialized as in struct T t = {42}; is t.y guaranteed to be 0 or is this an implementation decision of the compiler? ...

Mismatch between constructor definition and declaration

I had the following C++ code, where the argument to my constructor in the declaration had different constness than the definition of the constructor. //testClass.hpp class testClass { public: testClass(const int *x); }; //testClass.cpp testClass::testClass(const int * const x) {} I was able to compile this with no warnings usi...

Use RegisterDeviceNotification() for ALL USB devices.

I currently have some code that sets up notifications of connected USB HID devices within a Windows Service (written in C++). The code is as follows: GUID hidGuid; HidD_GetHidGuid(&hidGuid); DEV_BROADCAST_DEVICEINTERFACE NotificationFilter; ZeroMemory(&NotificationFilter, sizeof(NotificationFilter)); NotificationFilter....

Testing Bits To Create A String - Is there a better approach?

This code works, but I'm wondering if there is a better way to do it. Basically I need to test bits, and write the appropriate character or characters to a string depending on the state of the bit. The spaces are present because the characters will be displayed with a fixed width font and I'd like to keep them from moving around. C or...

Where does Intel C++ Compiler store the vptr ( pointer to virtual function table ) in an Object ?

Where does Intel C++ Compiler store the vptr ( pointer to virtual function table ) in an Object ? I believe MSVC puts it at the beginning of the object, gcc at the end. What is it for icpc ( Intel C++ Compiler )? ...

Can't convert function pointer argument

The error I'm getting: error C2664: 'v8::FunctionTemplate::New' : cannot convert parameter 1 from 'v8::Handle<T> (__cdecl *)(const v8::Arguments &)' to 'v8::InvocationCallback' Relevant definitions: typedef Handle<Value> (*InvocationCallback)(const Arguments& args); template<class C> class V8ScriptClass { public: template<cla...

Problems with setting application icon

(I'm using Visual Studio 2008, though I remember having similar problems with older versions as well.) I've tried several different methods (many of them mentioned in this other question), but I am still having some strange issues: When including an icon as a resource, it does show up as the executable file's icon immediately, but for...