c++

Why can't the linker prevent the C++ static initialization order fiasco?

EDIT: Changed example below to one that actually demonstrates the SIOF. I am trying to understand all of the subtleties of this problem, because it seems to me to be a major hole in the language. I have read that it cannot be prevented by the linker, but why is this so? It seems trivial to prevent in simple cases, like this: // A.h ...

Taking user input with pointers

I'm trying to get better at using pointers, and not using array notation. So I have a function to read user input and return a pointer to that array. I can do it like this and it seems to work ok: float *GetValues(float *p, size_t n) { float input; int i = 0; if ((newPtr = (float *)malloc(n * sizeof(float))) == NULL) ...

How to return a generic iterator (independent of particular container)?

I'd like to design a class Foo that stores various data of different types and returns iterators over them. It's supposed to be generic, so the user of Foo does not know how the data is stored (Foo could be using std::set or std::vector or whatever). I'm tempted to write an interface like this: class Foo { class FooImpl; FooImpl* i...

C++ Program Always Crashes While doing a std::string assign

I have been trying to debug a crash in my application that crashes (i.e. asserts a * glibc detected free(): invalid pointer: 0x000000000070f0c0 **) while I'm trying to do a simple assign to a string. Note that I'm compiling on a linux system with gcc 4.2.4 with an optimization level set to -O2. With -O0 the application no longer cras...

HTML renderer drop-in, C++ code

I want to drop in an HTML renderer that will basically be used for render-to-texture operations. If I can render the HTML to an HDC, that would be perfect. I found HTMLayout, which isn't bad. But it isn't open source. But I'm wondering if there's a way to somehow tap into IE or Mozilla/Gecko code, how realisitic/difficult this will b...

Check file access, get process id

Hi, is it possible to check if a file in a specific directory is accessed by a process X and get the process id (in c++ or better c#) ? I think there must be a moment, when the file is accessed by a process before it is opened by it. (for example anti-virus tools are using this too) Example: I double-click a txt file Before notepad i...

Is it safe to use boost serialization to serialize objects in C++ to a binary format for use over a socket?

I know that you can use boost serialization to serialize to a text format and then push over a socket, but I'd like to serialize a class of statistics data into a binary format (both for size and encoding/decoding overhead reasons). Is it safe to use boost serialization for this? My specific worries are: Differences between intege...

How do i create a unicode filename in linux?

I heard fopen supports UTF8 but i dont know how to convert an array of shorts to utf8 How do i create a file with unicode letters in it? I prefer to use only built in libraries (no boost which is not installed on the linux box). I do need to use fopen but its pretty simple to. ...

Vim C C++ syntax highlighting

In the latest Vim: Is there a way to define a '{' such that it's ignored by the C/C++ compiler (g++) but treated like a '{' in Vim synatx highlighting? I've tried //{ but it's ignored by Vim too. ...

How to use boost bind with a member function

The following code causes cl.exe to crash (MS VS2005). I am trying to use boost bind to create a function to a calls a method of myclass: #include "stdafx.h" #include <boost/function.hpp> #include <boost/bind.hpp> #include <functional> class myclass { public: void fun1() { printf("fun1()\n"); } void fun2(int i) {...

How to write a AVI decoder in a windows dialog using OpenGL,C++?

How to show AVI files in a windows dialog using OpenGL,C++? ...

Getting a pointer to a 4-byte object.. in an implementation independent way

I was programming normally when I realized that its probably not perfectly safe to assume an int is going to be a pointer to something 4 bytes in length. Because Some of the aspects of C++’s fundamental types, such as the size of an int, are implementation- defined.. What if you're dealing with something (like a waveform, for example) ...

question about recompiling the library in C++

Suppose my class is depending on other library. Now I need to modify the class for one application. What kind of modification will force me to recompile all libraries. What's the rule to recompile all libraries? for example, I only know the case 2) is like this. What about the others? 1) add a constructor 2) add a data member 3) chan...

Render webbrowser control offscreen (or hidden)

I have a small application which embeds webbrowser controls. In that application I have created a popup class. This popup is used to display server generated error messages. I want to be able to resize the popup to suit the message. This is so a short message is not contained in an oversize form and a large message is not in an undersiz...

Seeding constantly with Performance Counter?

Does seeding every time you use the random function with QueryPerformanceCounter() cause it to work poorly? Is there an algorithm for testing the quality of a random algorithm? ...

Point-in-poly for QPainterPath with holes

I'm trying to use a QGraphicsPathItem to represent a polygon with a hole in it (think doughnut). I can get it to draw correctly, and the center is transparent. However, with item selection or movement turned on, I am able to interact with my object when clicking in the hole. I'd rather treat the hole as not part of the polygon. I've d...

Reading socket reply in loop

Hello, I have: char buf[320]; read(soc, buf, sizeof(buf)); //print buf; However, sometimes the reply is much bigger then 320 characters, so I'm trying to run the read in a loop to avoid taking up too much memory space. I tried read(soc, buf, sizeof(buf)) but that only prints the same first x characters over again. How would I print ...

why must we normalize a vector

Just curious, I am reading a book on game AI. And one of the terms that is being used is to normalized a vector. Which is to turn a vector into units. To do so you must divide each dimension x,y and or z by its magnitude. We must we turn a vector into units before we do anything with it. Why ??. and could anyone give a scenario's . Thank...

How to start on blue-tooth device programming?

What languages , sdk's would I need to start bluetooth programming? ...

Are destructors not meant to be called when returning that object (not as a pointer)?

I have a function: static Bwah boo(){ Bwah bwah; return bwah; } And a main function: int main(){ Bwah boo = Assigner::boo(); cout << "got here.." << endl; } The destructor to Bwah is only called once, after the "got here" print. Is this guaranteed or is this a compiler optimization? ...