pointers

Function Pointers in Objective C

Hey Everyone! Quick question. Does anyone know how to get the function pointer of an objective c method? I can declare a C++ method as a function pointer, but this is a callback method so that C++ method would need to be part of the class SO THAT IT CAN ACCESS THE INSTANCE FIELDS. I don't know how to make a C++ method part of an objectiv...

C Programming: address of a label

I know everyone hates gotos. In my code, for reasons I have considered and am comfortable with, they provide an effective solution (ie I'm not looking for "don't do that" as an answer, I understand your reservations, and understand why I am using them anyway). So far they have been fantastic, but I want to expand the functionality in s...

String Comparisons - C

Hello all. I'm trying to write a string routine in C, and I keep hitting on the same issue. In C, I have this string: MAMAAMAAALJ If I have this string: AAA How can I determine that AAA is inside of MAMAAMAAAJ? ...

Returning a pointer vs. passing a reference to an object to store the answer in C++

I have general question regarding the use of pointers vs. references in this particular scenario. Let's say that I have a function that is going to do some computation and store the value inside an object for later use by the caller. I can implement this by using either pointers or references. Although, I would prefer using references ...

Weird result printing pointers as float in C

I know this is wrong and gcc will give you a warning about it, but why does it work (i.e. the numbers are printed correctly, with some rounding difference)? int main() { float *f = (float*) malloc(sizeof(float)); *f = 123.456; printf("%f\n", *f); printf("%f\n", f); return 0; } Edit: Yes, I'm using gcc with a 32-bit mach...

Dynamic Allocation of an Array of Pointers to Objects

Hi all, This question is in C++. I am trying to dynamically allocate an array of pointers to objects. I know I can use a vector container but the point of the exercise is not to... Here is the code: void HealthClub::AddHealthClubDevice ( char* HealthClubDeviceName ) { //We added NumberOfDevices as ...

how does this pointer assignment work?

I'm looking at a strcpy example where they increase the value of a pointer, and assign it in 1 line, like this: *ptrA++ = *ptrB++; I know that the value where the pointer is pointing to in the char array is increased, and the contents is copied. does c do something like *ptrA = *ptrB; ptrA++; ptrB++; in the background ? ...

IE8 and jQuery null pointers

hey guys: I've been building a website with some animated rollovers, where I animate the background image to give a colour fade effect. It works fine in FF3, Safari, chrome, but IE8 throws the "undefined is null or not an object" error. Full text: Message: 'undefined' is null or not an object Line: 22 Char: 16 Code: 0 URI: http://www.p...

NULL Pointer Problem?

void Insert(AVLnode * & root, string X) { if ( root == NULL) { root = GetNode(X); } else if ( root->info > X ) { Insert(root->left,X); if ( height(root->left) - height(root->right) == 2 ) if ( X < root->left->info ) RotateRR(root); else RotateLR(root); } else if ( root-...

Get the number of elements in a pointer to a char array in C++

I realise this is an incredibly noob question, but I've googled for it and can't seem to find an answer (probably because I've worded the question wrong... feel free to fix if I have) So I have this code: int main(int argc, char* argv[]) { puts(argv[1]); return 0; } It works fine if I've passed a parameter to my program, but ...

Similarities and differences between arrays and pointers through a practical example

Given the following code: #include <stdio.h> #include <stdlib.h> int main() { int a[1]; int * b = malloc(sizeof(int)); /* 1 */ scanf("%d", &a); printf("%d\n", a[0]); /* 2 */ scanf("%d", &b); printf("%d\n", b[0]); return 0; } the following warnings are obtained when it is compiled (i686-apple-d...

C struct problem

I am a C beginner, and I am curious why this gives me a Seg Fault everytime: #include <stdio.h> #include <stdlib.h> struct Wrapper { int value; }; int main () { struct Wrapper *test; test->value = 5; return 0; } I know I don't fully understand pointers yet, but I thought that struct_ptr->field is the same as (*struc...

Untyped Pointer in Pascal

What can I do with untyped pointers in Pascal? (Why untyped pointers are good?) ...

Flash AS3: How to gradually limit rotation of an object influenced by y position of mouse

Hi, I have created a flash app in which there is a circle with circles plotted along it's circumference, it is rotated when the mouse is moved up or down. The rotation is drawn directly from the y position of the mouse pointer. What I would like to do is grade the movement some how so that the further down the mouse pointer goes the les...

Why use a pointer to a pointer to the stack when creating a push function?

I am looking at a textbook example of a linked list that implements a stack. I don't understand why using a pointer to a pointer to the stack is necessary for the push operation. See the following example: bool push( Element **stack, void *data) { Element *elem = new Element; if(!elem) return false; elem->data = data; e...

Objective C - Change the values within NSArray by dereferencing?

Hi everyone, I've come across a problem related to pointers within arrays in objective-c. What I'm trying to do is take the pointers within an NSArray, pass them to a method, and then assign the returned value back to the original pointer(the pointer which belongs to the array). Based on what I know from C and C++, by dereferencing th...

Questions about vector, union, and pointers in c++

The question I have are NOT homework questions, but I am considering using these concepts in my assignment. The content,if it helps, is like this: I need to keep track of several union instances and they belong to my own union in one of my own class as class variables. (Note: the number of union instance is unknown, so I cannot just have...

Pointer reference?

Hi, I'm pretty new to iPhone application development and I'm doing well so far. But at one point my App doesn't do what it is intend for... It's a tableview based app and i'm pushing a new controller onto the stack to get some Userinput, but when the controller is popped again the data is somehow gone. Perhaps I've missunderstood somethi...

Why do I see 64-bit pointers in C++ on my 32-bit Mac OS X system?

So I've read a lot of related posts on SO and elsewhere such as: http://stackoverflow.com/questions/399003/is-the-sizeofsome-pointer-always-equal-to-four It makes total sense to me that on a 32-bit system I would expect 4-byte pointers and on a 64-bit system I would expect 8-byte pointers. So I'm running this code: int main() { cou...

Creating a pointer class a bad idea? (C#)

Hi, I have a bit of a design dilemma at present. I have an abstract class Firmware which handles file transfer (updating the firmware) and a few other things such as version. The trouble is that I want to update the file paths of all MyFirmwares in all Devices that I have over the place. One way I can do this is to have a static list of...