c++

Structure alignment in C++

struct Vector { float x, y, z; }; func(Vector *vectors) {...} usage: load float *coords = load(file); func(coords); I have a question about the alignment of structures in C++. I will pass a set of points to the function func(). Is is OK to do it in the way shown above, or is this relying on platform-dependent behavior? (it works ...

End of File(EOF) of Standard input stream (stdin)

Does stdin has any EOF? For e.g - If i start reading from stdin using fread/read then when the following loop will end? while ((c = read(0, buffer, BUFSIZ)) > 0) { . . . } If the solution of above is no the is there any way of added EOF in the stdin? ...

How to split audio or write demuxer filter in directshow?

I need to split a PCM audio stream with up to 16 channels into several stereo streams. As I haven't found anything capable of doing that, I'm trying to write my first directshow filter. Anything capable of splitting the audio would be very welcomed but I'm assuming that I must do it so there's what I've done: At first, I tried to creat...

Problems regarding Boost::Python and Boost::Threads.

Me and a friend are developing an application which uses Boost::Python. I have defined an interface in C++ (well a pure virtual class), exposed through Boost::Python to the users, who have to inherit from it and create a class, which the application takes and uses for some callback mechanism. Everything that far goes pretty well. Now, t...

Control a shell program through command line, giving it multiple instructions/data

I need to control a program in c++ (windows), I need to call it, then pass data to it as I collect it, finally after a certain command that program will use that data. I need to open the prog.exe and then line by line or value by value supply it information, it works manually through cmd. I have tried system() but this will stop after ...

Avoid global variables/methods name clashes when using C headers in C++

I recently spent some time chasing an annoying little bug and I'm looking for suggestions for those of you who have either encountered the same problem or know the best way to avoid it. I have a situation where I am developing in C++ and using strerror and as a result I am using something similar to extern "C" { #include <string.h> } ...

DSSCL_EXCLUSIVE not giving exclusive audible output. DirectSound

Hi guys, Very simple question. In the MSDN documentation for the DirectSound API they state that when my application is in focus it will be the only audible program. This is exactly what I want to happen, however when setting this flag and playing sound through my application, I can still hear the background music on my computer. So t...

using variables to decide type of class or namespace

Alright, so i had the bright idea of using namespaces and an if statement to change the outcome of variables, in PHP i imagine i could've used concatenation however c++ doesnt seem to have concatenation as far as i can see so far. so is there a way to get this code to work? namespace Blue { int seven = 7; int eight = 8; } namespac...

C++: Initialize a member pointer to null?

I have a class that looks like: class Foo { public: Foo(); virtual ~Foo(); private: Odp* bar; }; I wish to initialize bar to NULL. Is this the best way to do it? Foo::Foo() : bar(NULL) { } Also, is it necessary that the destructor is virtual? (If that is true, then must the constructor be virtual as well?) ...

risk related to using winPcap in place of socket

What I have read so far, winPcap allows you to bypass OS and bypass application and transport layer processing for TCP and provides direct access to the link layer. I am planning to use winpcap to do some user application stuff and not just sniffing. I will be receiving and sending critical information using pcap which I am currently do...

C++: Where to start when my application crashes at random places?

Hi, I'm developing a game and when I do a specific action in the game, it crashes. So I went debugging and I saw my application crashed at simple C++ statements like if, return, ... Each time when I re-run, it crashes randomly at one of 3 lines and it never succeeds. line 1: if (dynamic) { ... } // dynamic is a bool member of my class...

Length of boost::iostream::basic_array_sink/source

I'm using to do some serialization stuff "as it can be seen here". That worked fine, but I couldn't figure how to get the size of the written buffer.I've searched on boost documentation and apparently there is no way to do this aside of building a sink/source by myself? Thanks ...

Convert Float to Integer Equivalent

I want to convert a floating point user input into its integer equivalent. I could do this by accepting an input string, say "-1.234" and then I could just explicitly convert each character to it's decimal representation. (big endian by the way). So I would just say for the example I gave, -1.234 = 1|01111111|00111011111001110110110 ...

Size of #define values

If a value is defined as #define M_40 40 Is the size the same as a short (2 bytes) or is it as a char (1 byte) or int (4 bytes)? Is the size dependent on whether you are 32-bit or 64-bit? ...

Are empty initializers preferred for default initializing integral members?

I just read a comment by GMan that class A { public: A() : m_ptr() // m_ptr is implicitly initialized to NULL { } }; should be preferred over class A { public: A() : m_ptr(NULL) // m_ptr is explicitly initialized to NULL { } }; Notice the lack of NULL in the first example. Is GMan right? This might kinda ...

When is the const operator[] called and when is the non-const operator[] called?

I have two very different behaviors for reads and writes. In the event of reads, I want to copy a buffer of a rather hard to extract data structure. On writes, I will just write unbuffered to the structure. Up to now, I have been using operator[] to do access, so for the sake of polymorphism I'd like to continue doing so. So my quest...

Float to String Arduino Compile Error

I'm using this library to convert a float to a string: http://www.arduino.cc/playground/Main/FloatToString?action=sourceblock&amp;ref=1 . This is the snippet of code, where printing out flt looks like "29.37": float flt = tempSensor.getTemperature(); char buffer[25]; char str[20]; Serial.print(floatToString(str, flt, ...

C++: Difficulty with removing an item from a vector

I'm trying to remove an element from a vector. vector<Foo> vecFoo; Foo f1; Foo f2; Foo f3; vecFoo.push_back(f1); vecFoo.push_back(f2); vecFoo.push_back(f3); Foo* pF1 = &f1; vecFoo.erase(std::remove(vecFoo.begin(), vecFoo.end(), *pF1), vecFoo.end()); That last line produces a huge amount of C2784 errors. What am I doing wrong? (Ye...

Fastest C++ map?

Correct me I'm wrong but std::map is an ordered map, thus each time I insert a value the map uses an algorithm to sort its items internally, which takes some time. My application gets information regarding some items on a constant interval. This app keeps a map which is defined like this: ::std::map<DWORD, myItem*> At first all item...

Cross-compiling python extensions under Linux using distutils

Hello, everybody! Is there any way to compile both Windows and Linux versions of Python/distutils/SWIG/C++ extensions under Linux? As far as I understand the problem is at least in obtaining windows version of python-dev. Thank you. ...