c++

C++ help (Bisection/Newtons Method)

I need to write a class that includes a bisection and newton function. I understand how each method works, I just need to know how to write a class that passes the parameters of each function correctly. Parameters: Bisection The function you're finding the root of the starting interval (a,b) the absolute tolerance the relative...

How to get the size of the used space in an array? (NOT sizeof); c++

#include<iostream> using namespace std; int main() { char arr[200]; while(1) { cin >> arr; int i = sizeof(arr); cout << "The arr input is "<< arr << " and the size of the array is "<< i << endl; } return 0; } For the input of 34, This code outputs :The arr input is 34 and the size ...

Read GOT entry in Elf Binary

Hi, I want to write a little function's tracer. I use ptrace. I'm on ubuntu x86_64. I want to found the address of the shared library function (like printf). But i have some problem and some question about the Global Offset Table. I have the following code: size_t baseAddress = this->getBaseAddress(); Elf_Ehdr const * headerElf = sta...

FxCop (or equivalent) for non-.Net C++ code

Is there a way to get FxCop to analyze unmanaged C++ code? Setting the /clr flag allowed FxCop to open the .exe. It find a LOT of C++ items, but the analysis on the code is very weak. For example, the following code was skipped: int i=0; if (i=2) printf("Don't worry..everything will be okay."); I would like a tool that can catch t...

Detecting / avoiding g++ symbol collisions

Is there a way to detect and avoid if two shared libraries both expose the same global scope symbols? We recently ran into a situation where we had libA.so that exported the SuperCoolMethod() and libB.so that also exposed the SuperCoolMethod() which would clobber the previous copy of said method. This is on Linux using g++ 4.0 and late...

C++ Confused about Threads

Basicly this is what I have: Server:: Server (int port) { cout << "Initializing server.\n"; (...) pthread_t newthread; pthread_create(&newthread, NULL, &Server::_startListening, NULL); cout << "Exit\n"; pthread_exit(NULL); // <-- Question } void* Server::_startListening (void* param) { cout << "Start l...

Slow writing to array in C++

Hi everyone, I was just wondering if this is expected behavior in C++. The code below runs at around 0.001 ms: for(int l=0;l<100000;l++){ int total=0; for( int i = 0; i < num_elements; i++) { total+=i; } } However if the results are written to an array, the time of execution shoots up t...

Software to track several memory errors in old project?

Hello, I am programming a game since 2 years ago. sometimes some memory errors (ie: a function returning junk instead of what it was supposed to return, or a crash that only happen on Linux, and never happen with GDB or Windows) happen seemly at random. That is, I try to fix it, and some months later the same errors return to haunt me. ...

Passing in member variables of a specified class.

I want to pass in the name of a member variable. I thought I could do this by template <typename T::*> void SetVal(T::* newval) { }; This obviously doesn't work, but hopefully gets across what I'm trying to do. I want to be able to set a certain member variable of the templated class. ...

Which is the best linux program for a C++ programmer?

I have always wanted to step away from windows and go completely linux, but the only thing that prevents me are the programs. The problem is that I am use to the intellisense in Visual Studio 2008. I have looked for many alternatives to a program which displays the functions as visual studio does, but none seem to have what I am looking ...

The relationship between iterators and containers in STL

Good Day, Assume that I am writing a Python-like range in C++. It provides all the characteristics of Random Access containers(Immutable of course). A question is raised in my mind about the following situation: I have two different iterators, that point to different instances of the range container. The thing is that these two ranges ...

Break out of an overloaded extraction operator? (C++)

I'm trying to use an overloaded ">>" to scan input from a file. The problem is, I have no idea how to deal with end of file. In this case, my file is composed of a number, followed by several chars Ex: 9rl 8d 6ff istream &operator>>(istream &is, Move &move) { char c; int i = 0; c = is.get(); if (!isalnum(c)) return...

Fastest way to convert 16.16 fixed point to 32 bit float in c/c++ on x86?

Most people seem to want to go the other way. I'm wondering if there is a fast way to convert fixed point to floating point, ideally using SSE2. Either straight C or C++ or even asm would be fine. ...

how break the 64 limit when using WSAEventSelect

i develop an echo server with WSAEventSelect. It only allow 64 connections. What should i do. ...

How do I append a string to a char?

How do I append a string to a char? strcat(TotalRam,str); is what i got but it does not support strings ...

position.hh:46: error: expected unqualified-id before ‘namespace’

Here's my code: 34 35 /** 36 ** \file position.hh 37 ** Define the example::position class. 38 */ 39 40 #ifndef BISON_POSITION_HH 41 #define BISON_POSITION_HH 42 43 #include <iostream> 44 #include <string> 45 46 namespace example 47 { 48 /// Abstract a position. 49 class p...

Using Mysql blocking API with Boost::asio

I am building a aync single threaded server that receives data from clients. It processes the data and then saves it to the MySQL Database. The problem is that, MySQL C API does not support non-blocking calls and asio mainly does not like blocking calls. So I am thinking something like Python Twisted's deferToThread() like semantics. I...

Initialization of list with for_each to random variables

I'm trying to initialize a list to random integers using a for_each and a lambda function. I'm new to boost.lambda functions so I may be using this incorrectly but the following code is producing a list of the same numbers. Every time I run it the number is different but everything in the list is the same: srand(time(0)); theList.resiz...

UseQueryResult is not a member of mysqlpp

That's the error I get when I run this code : if(mysqlpp::UseQueryResult res = conn.query(sql).use()) Whats more interesting is that the next line doesn't have any problems while(mysqlpp::Row row = res.fetch_row()) Really driving me crazy. I've even manually included result.h I tried all combos of these include result.h, mysql++...

C++ using getline() prints: pointer being freed was not allocated in XCode

I'm trying to use std:getline() but getting a strange runtime error: malloc: * error for object 0x10000a720: pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug This is the code that produces this error: //main.cpp #include <iostream> #include <sstream> int main (int argc, char * const argv[]...