c++

kernel function parameter as const

say I have a kernel foo(int a, int b) { __shared__ int array[a]; } it seems a has to be a constant value, I added const in front of int. It sill didn't work out, any idea? foo(const int a, const int b) { __shared__ int array[a]; } ...

How to debug win 32 process to find memory access violation?

I have Agent installed on remote machine, this agent behave like process works in background, the process open socket connection with port number. The problem: this agent was exploited by security company, I am as QA want to find the problem for fix it. I have Perl script that able to connect to the agent by socket connection and send so...

Using RakNet source with Code::Blocks on Ubuntu

Hey Forum, So i'm trying to find out how to use the source files from RakNet with Code::Blocks, in Ubuntu. All the tutorials on the internet are for windows, or use windows ".lib files". I need to find a way to get this working but I'm getting very discouraged since this is my third day in a row that has been without result. If anyone c...

Assertion failure before program even starts

What is going on?! I fixed some structs, extensive amount of search/replace in my code. Then i finish and everything compiles fine, but the program crashes immediately. This is my main function: int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ exit(1); In all logics it shouldnt cras...

In regards to for(), why use i++ rather than ++i?

Perhaps it doesn't matter to the compiler once it optimizes, but in C/C++, I see most people make a for loop in the form of: for (i = 0; i < arr.length; i++) where the incrementing is done with the post fix ++. I get the difference between the two forms. i++ returns the current value of i, but then adds 1 to i on the quiet. ++i first ...

C++ vector of vectors

Hey everyone! I am trying to write a program that uses a base class to define an algorithm for solving a simple problem. I use a vector of ints as a 'game board'. My question is how can I create a function get_moves that returns a vector of game boards? Here is the code I have for the function: std::vector< <std::vector<int> > takeawa...

Help with Makefile: No rule to make target

CC = g++ CFLAGS = -Wall RM = /bin/rm -rf BIN_DIR = ifeq "$(DEBUG)" "1" BIN_DIR = Debug else BIN_DIR = Release endif OBJS = \ $(BIN_DIR)/Unit.o $(BIN_DIR)/%.o: src/%.c @echo Building "$@" @g++ -c "$<" -o"$@" all: $(OBJS) clean: $(RM) $(BIN_DIR) .PHONY: all clean However, when I try to build my project this, it gives m...

extracting last 2 words from a sequence of strings, space-separated

I have any sequence (or sentence) and i want to extract the last 2 strings. For example, sdfsdfds sdfs dfsd fgsd 3 dsfds should produce: 3 dsfds sdfsd (dfgdg)gfdg fg 6 gg should produce: 6 gg ...

Filtering out invalid user inputs

I'm trying to filter out invalid user inputs in a small C++ program using the following chunk of code: int selection = -1; while (!(selection >= 1 && selection <=4)) { cin >> selection; if (!(selection >= 1 && selection <=4)) { cout << "invalid selection!" << endl; cout << ...

How to delete a pointer to a pointer?

In C++, if you pass a pointer to a pointer into a method, do you delete the referenced pointer first? Do you have to clean it up within the method? I'm checking memory in task manager and it is leaking! Thanks!! ...

system() to c++ without calling cmd.exe

how can I run system("") without showing cmd.exe? I use cstdlib header code::blocks 10.5 I saw this question for c# but I don't know c# ;) ...

while loop loops infinitely when wrong input is entered

Why does the following loop infinitely when a wrong input is entered? How do I correct this? int operation; while (true) { cout << "What operation would you like to perform? Enter the number corresponding to the operation you would like to perform. "; cin >> operation; if (operation >= 1 && operation <= 5) b...

Forward declaration issues

Here is my issue. I have 2 classes which I want to implement in 1 h file lets call them class Foo and class Bar. My issue is that Bar has functions which have a return value of Foo and Foo has functions with a return value of Bar. Therefore, how do I properly forward declare these so they can play nice with each other. Thanks ...

Problem with running c program on mac?

Hi guys. I'm a total beginner in C programming so please bear with me. I have just started today and wanted to write a short program - well at least a small script that would just print out a line of text. Now here's what I did in order to achieve this: I downloaded vim text editor and wrote this few lines of code: #include <stdio.h> i...

Testing with Visual Studio Test 2010

Does any one know if I can test native code in VS Test 2010? ...

Creating a library?

I'm using MSVC, but I plan to make my library cross platform. Right now, I have h and cpp files of classes and functions. Is making a library in MSVC as simple as adding all my files to a Visual C++ Project marked as either Static or Dynamic Library? Or must I make my classes and functions extern and whatnot? Thanks ...

Is it possible to use System C data types in C++ without the entire System C kernel?

System C provides arbitrary length integer types that can be manipulated either as numbers (i.e. with support for artihmetic) or as bit-vectors (i.e. with support for logic operations and working with sub-vectors). System C also provides support for all sorts of other things I don't want, such as clocks, flip flops and such, as well as ...

Programmatically add port forwarding entry into router using upnp?

Does someone have a simple example on how to add a port forwarding entry with upnp into the router using c++? ...

Adding includes causes compilation error

Compiling with Visual Studio 2005, on Windows XP. I add the following headers to my "stdafx.h" file like so: #include <atlbase.h> #include <atlcom.h> #include <atlcore.h> #include <atlstr.h> (technically the same error appears with just atlbase.h included) which produces the following errors: error C2334: unexpected token(s) precedi...

boost example failed to build

Hello, I'm a newbie about boost. I compiled boost libraries with success (under mac os x). Now, I tried to build the very first example mentioned at boost website (including boost/ as include directory and boost/stage/lib as library directory, with netbeans) and got the following error "/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAK...