c++

How to implement a timer with interruption in C++?

I'm using the GCC compiler and C++ and I want to make a timer that triggers an interruption when the countdown is 0. Any Ideas? Thanks in advance. EDIT Thanks to Adam, I know how to do it. Now. What about multiple timers running in parallel? Actually, these timers are for something very basic. In NCURSES, I have a list of things. W...

Linux C++ threads are dead, but "hanging" - thread limit

A friend of mine is trying to fix up a custom http server in C++ written for windows to work in Linux. I tried to help him, but all I found seemed too obvious. The app creates a thread for every time a request comes in. The thread serves the request and ends. After some number of requests (something over 300) new threads are not created...

Qt: How to detect the right clicked item when using customContextMenuRequested signal

hello all quick question im using in Treewidget the customContextMenuRequested signal and using using popup with qmenu How can I get the item pointer / object / reference that just bean right clicked before the popup executed I need to make some validation on the item ...

Windows current ThreadID without windows API call

Hey there! I'd like to query the current threadID without making a windowsAPI call. According to this http://en.wikipedia.org/wiki/Win32_Thread_Information_Block wikipedia article it should be possible to access the thread ID directly. I tried this code: void* tibPtr; __asm { mov EAX, FS:[0x18] mov [tibPtr], EAX } int* ptr...

How is *it++ valid for output iterators?

In example code, I often see code such as *it++ for output iterators. The expression *it++ makes a copy of it, increments it, and then returns the copy which is finally dereferenced. As I understand it, making a copy of an output iterator invalidates the source. But then the increment of it that is performed after creating the copy would...

C++0x closures / lambdas example

I am attempting to leverage C++0x closures to make the control flow between a custom lexer and parser more straightforward. Without closures, I have the following arrangement: //-------- // lexer.h class Lexer { public: struct Token { int type; QString lexeme; } struct Callback { virtual int processToken(const Token &token) = 0;...

OpenGL Multiple Viewports and gluPerspective()

Hello All, So I am trying to learn how to use glViewport(), "MULTIPLE TIMES". Below is my code, I have tried to follow others examples, but they are either so convoluted with other things not relevant to what I am doing or, I do not understand what they are doing. By the way I am using glut to manage my windowing system. So the best way...

Returning value from a function

const char *Greet(const char *c) { string name; if(c) name = c; if (name.empty()) return "Hello, Unknown"; return name.c_str(); } int _tmain(int argc, _TCHAR* argv[]) { cout << Greet(0) << '\t' << Greet("Hello, World") << endl; return 0; } I see 2 bugs with the above code. Returning c_str from...

What with the thousands of warnings in standard headers in MSVC -Wall

Some people seem to advise you use -Wall, but when I did it on a small test project which just has a main.cpp with some includes, I get 5800 warnings most of them in standard headers or in windows headers. Is that intended behaviour? How do I go about making my compilation warning free? Here are just a few for some reading fun: 1>c:\p...

How to make the read function not to hang?

I'm using socat to create a virtual serial port with: socat PTY,link=/dev/ttySV0,echo=1 PTY,link=/dev/ttySV1,echo=1 The in my program written in C++, I open the ttySV1 port and start to read. The read function is in a while, but the problem is that the read function hangs until I send data to the port. Do you know how to make the tah...

Issue with exceptions being caught by Win32 message dispatcher

This is kinda a very low-level type question, but maybe someone here has some insight... I'm having an issue where unhandled SEH exceptions (such as Access Violations) are seemingly being caught at the Win32 message dispatch level, rather than terminating the program. I found the following reference blog, which explains the problem, but...

How can I execute a Perl script inside C++ console application?

I am new to C++ programming :). I was wondering what would be the best and easiest approach for this problem. I have a C++ console application and a Perl script. Both of them are to be integrated. To be more specific need to write perl perlscript.pl arg1 in a cmd prompt (to execute the Perl script). perform few actions in C++ console a...

Looking to contribute to open source or ideas for something open source

I hold degrees in computer science and mathematics. Both of these fields are extremely interesting to me. I particularly like high performance computing, statistical computing, c++, distributed computing, and algorithms. I would very much like to experience open source programming but don't really have any ideas of my own and would like ...

Simple library or implementation for a mathematical expression evaluator

i have one text file that contains only one line the line only contains one math expression for example 12+(3.0*(4)-1)/sqrt(121) my program needs to read this express as string and then give the result 13 is there any simple way or 3rd party dll/lib to make this out? COMMENT ADDED: http://stackoverflow.com/questions/928563/code-golf...

Find fully qualified .NET assembly name programmatically (from simple name, for given .NET version)?

My goal is to display a .NET Windows forms message box from a pure C++ native Windows API-level program (not managed C++ or C++/CLI). That is, for learning purposes I want to implementing the C# code shown in the comment below, in pure C++: /* // C# code that this C++ program should implement: using System.Windows.Forms; n...

C++ MSVS dll headers #include issues

Hi, I don't code with lib linking and dll for most of the time, recently when I do, i realized there could be something very wrong with the way i do my #include. Is the following the correct/desirable way to do #include? suppose i have 3 projects (1) dll_A (2) dll_B (3) exe_1. dll_A depends on dll_B, exe_1 depends one dll_A. the way ...

Calling C code from managed code

I currently have a C function that I'd like to use in .NET (C#). I can see two ways of achieving this: Compiling it (I think this is possible) with /clr on VC++.NET, having implemented "façade" managed methods that call the C code. Compiling the C code as a DLL and then making API calls. What do you find best? How to do the first of...

socket programming in c++ or VC++.net

Hi, I am a new developer of C++ and i want to do socket programming in c++ or VC++.net. If you have good and easy to learn tutorial for socket programming in c/c++ please share the link. ...

create a GUi using window native API.

hello, i am trying to create a GUI only use native windows api. i create projects in vs 2008 using win32 console project and win32 window project, and i used the sample code from Microsoft as below #include <windows.h> // Global variable HINSTANCE hinst; // Function prototypes. int WINAPI WinMain(HINSTANCE, HINSTANCE,...

Chaining methods is giving me unexpected results, and the arguments are being evaluated in reverse order.

Cliffnotes: I've gotten method chaining to work as I expected in one case, but in another case, there is something funny going on. I expect these two example to have the exact same output: As expected example Not as expected example I've done a lot of chaining using Javascript, so when I learned that you can chain class methods in a...