c++

Double UDP socket binding in Linux

In C++, when I run (red alert! pseudo-code) bind(s1, <local address:port1234>) bind(s2, <local address:port1234>) on two different UDP sockets (s1 and s2 each created with a call to socket()) I get problems. In Linux (Ubuntu), the double binding seems to be fine. In Windows, however, the double binding fails, and the call to bind() th...

Inline Functions

I know compiler may or may not perform inline expansion of a function whether requested by the programmer or not. I was just curious to know, is there any way by which programmer can know for sure that compiler has inlined a particular function? ...

const reference to temporary and copying - C++

Please consider the following code, struct foo { foo() { std::cout << "Constructing!" << std::endl; } foo(const foo& f) { std::cout << "Copy constructing!" << std::endl; } ~foo() { std::cout << "Destructing.." << std::endl; } }; foo get() { foo f; return f; } int ma...

Template class, static function compile error c++

I have the following function defined inside my linked list class. The declaration in the header file looks like this: template <typename T> class RingBuffer { ...//stuff static BLink * NewLink (const T&); // allocator }; BLink is a "link" class within the RingBuffer class. The following implementation code: template <typename ...

C++: Cannot instantiate a pointer directly

This is an SDL problem, however I have the strong feeling that the problem I came across is not related to SDL, but more to C++ / pointers in general. To make a long story short, this code doesn't work (edited to show what I really did): player->picture = IMG_Load("player"); SDL_BlitSurface(player->picture, NULL, screen, &pictureLocati...

Printf used in unfamiliar fashion

I found this line of code when upgrading a C++ Builder project to RAD Studio 2009: mProcessLength->Text.printf("%d",mStreamLength); It doesn't compile in 2009, however what is the intent of this line and what is a better equivalent? Given that mProcessLength->Text is now a wchar_t*. ...

Program configuration data in Unix/Linux

What is recommended way to keep a user configuration data in Unix/Linux? My programming language is C++. Configuration data will be kept in XML/text/binary format, I have no problem with handling such files. I want to know where can I keep them. For example, in the Windows OS configuration data may be kept in the Registry (old way) or in...

how do i conbvert a gstreamer program to stream video via udp into Qt?

please help me convert this into a qt program. this is a gstreamer program to stream video via udp source. i need to implement this in Qt......the program i'm using is shown below.......... #include #include #include GstElement *pipeline, *source, *decoder, *video_s...

RAII and C++ STL

I have a case where I wish to store a list of resources in a std::vector. As I see it, my options are as follows: Give my resource a default constructor Store them as heap objects (and wrap them in a shared pointer) Option 1 makes it possible to construct invalid resources and option 2 forces me to use the heap. Am I missing any opt...

Accessing base class member variable from derived class, instantiated from derived class

Hello everybody, I have a problem to access a base class member variable from a derived class thru a interface containing 2 virtual functions. The main purpose is that I need to work with these classes at 2 different programn stages. First stage is to fill an array with text snippets / sentences thru the ArrayStemmedSnippet class The s...

Professional development and C++

C++ is my primary programming language. As most of professional programmers I know some others, but much less "fluently". I'm constantly mastering my skills in C++, reading forums (like this one), read books. And the process takes years ... I know that the language is only a tool, and there're other fields professional programmer must b...

Boost regex and confusing errors

I'm trying to use Boost regex to see if something has an integer in it. One of the examples on this page is bool validate_card_format(const std::string& s) { static const boost::regex e("(\\d{4}[- ]){3}\\d{4}"); return regex_match(s, e); } There's also a presumably working example here. But when I try it on my machine, I get f...

QProcess doesn't start java app under windows 7

Hi. I'm writing a windows application using Qt (4.6.1) that uses QProcess class to execute a java application. Here's basically the code: process = new QProcess(this); connect( process, SIGNAL( started() ), this, SLOT( onProcessStarts() ) ); connect( process, SIGNAL( finished(int) ), this, SLOT( onProcessE...

Serial port : Read data problem, not reading complete data

Hi I have an application where I am sending data via serial port from PC1 (Java App) and reading that data in PC2 (C++ App). The problem that I am facing is that my PC2 (C++ App) is not able to read complete data sent by PC1 i.e. from my PC1 I am sending 190 bytes but PC2 is able to read close to 140 bytes though I am trying to read in ...

Visual C++ Tail Call Optimization

According to answers to that question: Which, if any, C++ compilers do tail-recursion optimization? it seems, that compiler should do tail-recursion optimization. But I've tried proposed options and it seems that compiler can't do this optimization in case of template functions. Could it be fixed somehow? ...

Type casting in c++

In c++ can we cast an object to an integer ? Clarifying my question - Suppose i have created an interface that do all the file management thing like file create, open, read, write and i want to have a unique handle of every instance of a file so for this can i create a file handle from every instance of the file interface by just type ...

Setting up cURL library for MSVS

I'm trying to write a simple curl program to retrieve the web page in VC++ 8.0. #include <stdio.h> #include <curl.h> int main(void) { CURL *curl; CURLcode res; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se"); res = curl_easy_perform(curl); /* always cleanup */ ...

Sorting only using the less-than operator compared to a trivalue compare function

In C++/STL sorting is done by using only the less-than operator. Altough I have no idea how the sorting algorithms are actually implemented, I assume that the other operations are created implicite: a > b *equals* b < a == true a == b *equals* !(a < b) && !(b < a) Compared to using a trivalue* compare function, like for example Java, ...

Why does the following code not generate a warning in MSVC

I have a section of code that can be summarised as follows; void MyFunc() { int x; ' ' x; ' ' } I would have thought that simply referencing a variable, without modifying it in anyway or using its value in anyway should generate a warning. In VS2003 it does neither, and it I need lint to pick it up. I realise it doesn't effec...

Simplest way to validate a GPS string in C++?

I have some MET data I want to validate which would look something like these: char validBuffer[] = {"N51374114W1160437"}; char invalidBuffer[] = {"bad data\n"}; char emptyBuffer[] = {""}; I've tried a simple sscanf, but that failed: int _tmain(int argc, _TCHAR* argv[]) { char validBuffer[] = {"N51374114W1160437"}; char inva...