pointers

Retrieve data from const int * const buffer[]

I marshalled correctly to: IntPtr buffer Buffer is pointer to array of 2 pointers to arrays with respective data. The problem is that I get not accurate data, like if there's something missing in the data retrieved (e.g. missimg samples from stream of audio data). // length is parameter IntPtr[] temp = new IntPtr[2]; Marshal.Copy(buf...

How do you make sense of the error: cannot convert from 'int []' to 'int []'

When compiling the following code: void DoSomething(int Numbers[]) { int SomeArray[] = Numbers; } the VS2005 compiler complains with the error C2440: 'initializing' : cannot convert from 'int []' to 'int []' I understand that really it's trying to cast a pointer to an array which is not going to work. But how do you explain the ...

How do I delete the closest "Point" object in a STD::List to some x,y?

I have a point class like: class Point { public: int x, y; Point(int x1, int y1) { x = x1; y = y1; } }; and a list of points: std::list <Point> pointList; std::list <Point>::iterator iter; I'm pushing points on to my pointList (although the list might contain no Points yet if none have been pushed ye...

Cut out section of string

I wouldn't mind writing my own function to do this but I was wondering if there existed one in the string.h or if there was a standard way to do this. char *string = "This is a string"; strcut(string, 4, 7); printf("%s", string); // 'This a string' Thanks! ...

Allocating memory for triple pointer

Hi, I have a function which takes a triple pointer as an argument: int somefunction(tchar ***returnErrors); Does anyone know how to allocate the memory for the returnErrors parameter? Thanks! Niko ...

Which version of safe_delete is better?

#define SAFE_DELETE(a) if( (a) != NULL ) delete (a); (a) = NULL; OR template<typename T> void safe_delete(T*& a) { delete a; a = NULL; } or any other better way ...

C: What is the best way to modify an int pointer passed via a typedef?

I have a typedef int my_type and i have a function which looks like void my_func (my_type* x); How should I use this func to modify x using the best practice? ...

Trouble with pointers and references in C++

I have a PolygonList and a Polygon type, which are std::lists of Points or lists of lists of points. class Point { public: int x, y; Point(int x1, int y1) { x = x1; y = y1; } }; typedef std::list<Point> Polygon; typedef std::list<Polygon> PolygonList; // List of all our poly...

How am I accidentally overwriting when referencing these pointers?

Last question for tonight, I promise. These pointers are giving me a serious headache. I have a std::list<Point> called Polygon and a std::list of Polygons defined like: typedef std::list<Point> Polygon; typedef std::list<Polygon> PolygonList; // List of all our polygons PolygonList polygonList; I created the method below to att...

Passing arrays and matrices to functions as pointers and pointers to pointers in C

Given the following code: void foo( int* array ) { // ... } void bar( int** matrix ) { // ... } int main( void ) { int array[ 10 ]; int matrix[ 10 ][ 10 ]; foo( array ); bar( matrix ); return 0; } I don't understand why I get this warning: warning: passing argument 1 of ‘bar’ from incompatible poi...

Mis-aligned pointers on x86

Can someone provide an example were casting a pointer from one type to another fails due to mis-alignment? In the comments to this answer, bothie states that doing something like char * foo = ...; int bar = *(int *)foo; might lead to errors even on x86 if alignment-checking is enabled. I tried to produce an error condition after set...

Array of pointers problem

I have tried this example of array of pointers. I am getting the error "Illegal initialisation in function main" int main() { int a[]={1,2,3,4,5}; int b[]={1,2,3,4,5}; int c[]={1,2,3,4,5}; int *p[3]={a,b,c}; int i; clrscr(); for(i=0;i<3;i++) printf("%d - %u\n",*p[i],p[i]); getch(); } If I use stati...

C++ Pointer Snippet

Greetings everyone. This is my first question here at stackoverflow so please bear with me. My programming class this semester is Java; last semester was C++. My Java teacher feels (justifiably, I think) that it is very important for we students to understand the mechanics of memory management. Since Java has automatic garbage co...

UPDATE: C++ Pointer Snippet

Greetings again, and thanks once more to all of you who provided answers to the first question. The following code is updated to include the two functions per the assignment. To see the original question, click here. I am pretty sure this fulfills the requirements of the assignment, but once again I would greatly appreciate any assist...

Testing pointers for validity (C/C++)

Is there any way to determine (programatically, of course) if a given pointer is "valid"? Checking for NULL is easy, but what about things like 0x00001234? When trying to dereference this kind of pointer an exception/crash occurs. A cross-platform method is preferred, but platform-specific (for Windows and Linux) is also ok. Update for...

What is the difference between these two versions of code (pointer arithmetics & unicode) ?

I'm debugging some opensource code on a 64-bit Solaris system, using GCC, that converts 2byte characters (wchar_t) to 4byte characters (wchar_t). Because Solaris like some other Unixes define wchar_t as 4byte, not 2byte like in Windows. Now I fixed the problem, through laying it out the pointer arithmetic over two lines, but I'm not sur...

C++: question about pointers and references

I have a function which takes a reference to an object- void move(Ball& ball); I have another function calling 'move()' which has a pointer to ball - void foo(Ball* ball){ //call move() } How is foo() supposed to pass ball to 'move()'? Should it be like - move(*ball); or move(ball); or move(&ball); ...

What makes more sense - char* string or char *string?

Duplicate of this question. I'm learning C++ at the moment, and I'm coming across a lot of null-terminated strings. This has got me thinking, what makes more sense when declaring pointers: char* string or char *string ? To me, the char* format makes more sense, because the type of "string" is a pointer to a char, rather than a cha...

Publish/Subscribe and Smart pointer

I would like to implement a simple Publish/Subscribe pattern where: A single publisher publishes a token (a pointer to an object) to its subscribers. Publisher and subscribers are all independent threads. I plan to add thread-safe queue to each of the subscriber such that Publisher can keep distributing the tokens to the subscribers whi...

Java programmer - how do C++ people use classes? Pointers to classes, default parameters?

I know my way around object-oriented programming, but I'm used to Java, and I never touched C++ until recently. I think my problem is not so much related to syntax as to the philosophy of OOP in C++. I understand the difference between pointers and addresses and the stack and the heap, and stuff, but I still feel like I'm missing som...