I encountered an interesting situation today in a program where I inadvertantly assigned an unsigned integer to a std::string. The VisualStudio C++ compiler did not give any warnings or errors about it, but I happened to notice the bug when I ran the project and it gave me junk characters for my string.
This is kind of what the code lo...
Given the code below, why is the foo(T*) function selected ?
If I remove it (the foo(T*)) the code still compiles and works correctly, but G++ v4.4.0 (and probably other compilers as well) will generate two foo() functions: one for char[4] and one for char[7].
#include <iostream>
using namespace std;
template< typename T >
void foo(...
Hi,
I am very aware of compiling C++ programs with g++ in linux environment. But, may be I am missing something, I am getting this strange output/behaviour.
I have source file in test.cpp.
To compile this, I did
(1)
g++ -c test.cpp
g++ -o test test.o
./test
Everything works fine.
But when I did compling and linking in same stage, ...
Does a c++ shared library have its own memory space? or does it share the caller process' one?
I have a shared library which contains some classes and wrapper functions.
one of this wrapper function is kinda:
libXXX_construct() which initializes an object and returns the pointer to the said object.
Once I use libXXX_construct() in a c...
Possible Duplicate:
Good book for learning the C++ standard template library?
I am having very less knowledge on templates and STL. So looking for a good for STL.
...
How to compile open source framework in Visual Studio C++, that has "makefile" only and no solution file?
...
I have a shared library (namely libXXX.so) with a cpp/h file associated.
They contains a number of function pointers ( to point to .so function entrypoint) and a class to wrap this functions as methods of the said class.
ie: .h file:
typedef void* handle;
/* wrapper functions */
handle okUsbFrontPanel_Construct();
void okUsbFrontPanel_...
One of the exercises in C++ Primer Plus is having me use fstream to open a txt file and input data into a structure then output it. First line of the txt file is the number of "donors". The problem I seem to be having is that (I think) when I use "inFile >> value;" to retrieve the number and then allocate the structure via new, its expec...
In our project which supports multiplatform (Linux, Solaris, Windows) and coded in c,c++ , we are using ONC Rpc for IPC.
Recently there is a requirement to have an application server to work on two different programs no.
I have tried following to test.
Created a multithread application
Within that creted two worker threads
I...
I am trying to catch messages from an application for which I have no source code.
I install a Windows hook like this:
hhk = SetWindowsHookEx(WH_CALLWNDPROCRET, HookProcSetTextRet, hinst, threadID);
(The hhk variable is in shared data.)
I don't understand some of the behavior, though, specifically:
LRESULT CALLBACK HookProcSetTextRet...
I need to convert a C/C++ double to a 64 bit two's complement, where the Radix point is at bit number 19 (inclusive).
This means that for the format I want to convert to
0x0000 0000 0010 0000 is the number 1
0xFFFF FFFF FFF0 0000 is the number -1
0x0000 0000 0000 0001 is 0.95 x 10^-6
0xFFFF FFFF FFFF FFFF is -0.95 x 10^-6
So far ...
I'm mostly new to Visual Studio, so I apologize if this is a basic problem. I have a solution which contains a number of projects. In project A, I have a pre-existing set of files that I added a new class to. Project B uses the functionality coded in that new class in Project A. Project A is built first, and a .lib file is generated,...
I was reading this page :
C++ Tip: How To Get Array Length. The writer presented a piece of code to know the size of static arrays.
template<typename T, int size>
int GetArrLength(T(&)[size]){return size;} // what does '(&)' mean ?
.
.
.
int arr[17];
int arrSize = GetArrLength(arr); // arrSize = 17
Could anyone please shed the light o...
I would like to wrap the xmlrpc "call" function (which takes a variable number of parameters) with another function (also taking a variable number of parameters). I would like to simply forward the variable number of parameters I get passed in to my wrapper function to the xmlrpc "call" function.
I know how to use va_start and va_arg, b...
I'm aware that there is a realloc function that would allow me to resize the memory block (and it's paired with a free function). However, I'm trying to do the same to a c++ class with some member pointers allocated memory using new instead of realloc. Is there an equivalent keyword to realloc in c++ that would allow me to achieve the sa...
Hi,
My scenario: one server and (some clients (though not many). The server can only respond to one client at a time, so they must be queued up. I'm using a mutex (boost::interprocess::interprocess_mutex) to do this, wrapped in a boost::interprocess::scoped_lock.
The thing is, if one client dies unexpectedly (i.e. no destructor runs) ...
I am looking for web sites or books that would help a C++ developer to pick up C#.
So far, this is the best one I've found.
...
Yesterday I asked about C++ context sensitivity, see here. Among many excellent answers, here is the accepted one, by dmckee.
However, I still think there's something to be said about this (maybe some terminological confusion?). The question amounts to: what part of compilation deals with the ambiguity?
To clarify my terminology: A CFG...
Given:
int i = 42;
int j = 43;
int k = 44;
By looking at the variables addresses we know that each one takes up 4 bytes (on most platforms).
However, considering:
int i = 42;
int& j = i;
int k = 44;
We will see that variable i indeed takes 4 bytes, but j takes none and k takes again 4 bytes on the stack.
What is happening here? I...
I have a graph with four nodes, each node represents a position and they are laid out like a two dimensional grid. Every node has a connection (an edge) to all (according to the position) adjacent nodes. Every edge also has a weight.
Here are the nodes represented by A,B,C,D and the weight of the edges is indicated by the numbers:
A ...