pointers

Passing references to pointers in C++

As far as I can tell, there's no reason I shouldn't be allowed to pass a reference to a pointer in C++. However, my attempts to do so are failing, and I have no idea why. This is what I'm doing: void myfunc(string*& val) { // Do stuff to the string pointer } // sometime later { // ... string s; myfunc(&s); // ......

Length of an array of pointers

Hi, if I have an array of pointers like char **lines, how can i determine its length? Thanks ...

Convert IntPtr to int* in C#?

I have a C++ DLL returning an int* to a C# program. The problem is the int* in C# remains null after the assignment. When I assign the C++ result to an IntPtr, I get a correct non-null value. However any attempt to convert this to an int* results in null. I've tried: IntPtr intp = cppFunction (); // Non-null. int* pi = (i...

When to use restrict and when not to

I have a general understanding of restrict but I'm hoping to clarify some fine points. I have a function that reads a null-terminated string from one buffer and writes out a URL encoded version in another buffer. The function has this signature (currently without restrict): char const *StringUrlEncode(char const *unencoded, ...

What does having two asterisk ** in Objective-C mean?

I understand having one asterisk * is a pointer, what does having two ** mean? I stumble upon this from the documentation: - (NSAppleEventDescriptor *)executeAndReturnError:(NSDictionary **)errorInfo ...

What determines what is written to a C++ pointer when delete is called?

I have a pointer to a given class. Lets say, for example, the pointer is: 0x24083094 That pointer points to: 0x03ac9184 Which is the virtual function table of my class. That makes sense to me. In windbg, everything looks correct. I delete said pointer. Now at 0x24083094 is: 0x604751f8 But it isn't some random garbage, that ...

Warning while passing 2d array

I have the following function void initBoard(int * board[BOARD_ROWS][BOARD_COLS]){ int z = 0; for( z = 0; z<10; z+=1){ int l; for( l = 0; l<10; l+=1){ board[z][l] = 0; } } } and from main i call it like int plBoard[10][10]; initBoard(&pcBoard); when compiling it works but i get a warning saying: war...

K&R: array of character pointers

On pg. 109 of K&R, we see: void writelines(char *lineptr[], int nlines) { while (nlines -- > 0) printf("%s\n", *lineptr++); } I'm confused about what *lineptr++ does exactly. From my understanding, printf requires a char pointer, so we provide that with *lineptr. Then we increment lineptr up to the next char pointer in the array? Is...

Efficient coding help

I am currently writing code in C++ to find all possible permutations of 6 integers and store the best permutation (i.e. the one whose total is closest to a given value). I am trying to write this code as efficiently as possible and would apreciate any advice or examples. I was considering storing the integers in an array and performing...

Why are the pointers in my 64-bit ISAPI dll messed up?

I am working on migrating a 32-bit ISAPI dll to 64-bit. I am using Visual Studio 2008. I am having problems with the EXTENSION_CONTROL_BLOCK pointer in the HttpExtensionProc function. The char pointers within the EXTENSION_CONTROL_BLOCK structure are not valid on entry into the function; they are labeled with within the watch window....

Top 10 Frequencies in a Hash Table with Linked Lists

The code below will print me the highest frequency it can find in my hash table (of which is a bunch of linked lists) 10 times. I need my code to print the top 10 frequencies in my hash table. I do not know how to do this (code examples would be great, plain english logic/pseudocode is just as great). I create a temporary hashing list ...

Reusing a NSString variable - does it cause a memory leak?

Coming from a .NET background I'm use to reusing string variables for storage, so is the code below likely to cause a memory leak? The code is targeting the iphone/itouch so no automatic GC. -(NSString*) stringExample { NSString *result = @"example"; result = [result stringByAppendingString:@" test"]; // where does "example" go?...

Question About & operator in C++

I am looking at the .h file of a Wrapper class. And the class contains one private member: T* dataPtr; (where T is as in template < class T > defined at the top of the .h file) The class provides two "* overloading operator" methods: T& operator*() { return *dataPtr; } const T& operator*() const { return *dataPtr; } Both sim...

Making a game trainer in C++?

Ok so i've messed with games before, but now i would like to make a trainer only problem is that there memory adresses changes every time i play it on a different computer or restart the game. Now i need to find a pointer but have no idea how. So how do i find the pointer to the adress for ammo for any weapon with a memory scanner like ...

How to read 3rd party application's variables from memory?

Dears, I'm trying to read variables from memory. Variables, that doesn't belong to my own program. For instance, let's say I have this Adobe Shockwave (.dcr) application running in browser and I want to read different variables from it. How it's being done? Do I need to hook the process? But it's running under virtual machine, so I don'...

Reading and writing to a buffer

Hi, I have 2 classes, one that writes multiple 96bit objects to a buffer (32bits at a time - 3x int32), and one that i want to read from the same buffer. The first class (Writer) reserves and area of memory and creates a pointer to the first 32bit area. 1) How do I write to the buffer safely (ignoring buffer overflow for now)... I nee...

Why is 2[myArray] valid C syntax?

Duplicate In C arrays why is this true? a[5] == 5[a] Given an array myArray[5] = { 0, 1, 2, 3, 4 }; an element can be accessed as 2[myArray] Why? When I see this expression I'm imagining C trying to access the pointer "2" and failing to add "myArray" pointer increments to dereference that address. What am I missing? ...

C pointer arithmetic snippet

I have a program that I'm trying to decode. It is translated to C from another language (whose name is not spoken here), and as I want to understand how it works, I am slowly rewriting the code and simplifying it to use all the nice logical constructs C has to offer. The following little bit keeps popping up in my code, with varying val...

How large structs can be passed by value efficiently?

The rule of thumb is that it is okay to pass small structs by value and larger ones should be done pointers. My question is where exactly is this cutoff point? How large can the structures be before you are better off passing them by pointer. I know this will vary between platforms, but I assume some rough estimates could be given. A ...

C pointer to array/array of pointers disambiguation

What is the difference between the following declarations: int* arr1[8]; int (*arr2)[8]; int *(arr3[8]); What is the general rule for understanding more complex declarations? ...