pointers

How do disk pointers work?

Suppose I want to store a complicated data structure (a tree, say) to disk. The internal pointers which connect nodes in my data structures are pointers, but I can't just write these pointers to disk, because when I read the data structure back the memory locations will have changed. So what is the right way to store the pointers on di...

When is pointer to array useful?

I can declare: int (*ap)[N]; So ap is pointer to int array of size N. Why is this ever useful? If I pass it to function, what useful thing it can do with it that it could not do with just a normal pointer to the array's contents? C FAQ say: 2.12: How do I declare a pointer to an array? Usually, you don't want to. ...

Dealing with char ** argv

How do I assign a sequence of character strings to a char ** argv variable in a program? Its a command line argument. I'm currently trying to convert an .exe app to a dll. For example: { "string1", "string2", "string3" } --- > char ** argv variable My problem is somehow realted to this: http://stackoverflow.com/questions/1015944/ho...

How to reassign `this` pointer inside object member function?

I have an interesting question about C++ pointers. You probably will think that I have to change my design, and avoid doing what I am doing, and you are probably right. But let's assume that I have a good reason to do it my way. So this is the situation. I have a C++ class TestClass, and I have a pointer A of this type: TestClass* A =...

c function pointers

This program sorts lines alphabetically/numerically depending on the arguments passed to main. And im working on this exercise from k&R now: Add the option -f to fold upper and lower case together, so that case distinctions are not made during sorting; for example, a and A compare equal. Is what i wrote in my_strcmp good? And will it w...

Question About Why String is Truncated on First Instance of \0

I have a function which reads in a character, one byte at a time, through the serial port. After these bytes are collected, they are passed to a method to process the bytes and message. I know how to fix the problem (fix is below), but why do my bytes get truncated when I don't perform the fix? unsigned char dpBuf[255]; ... // Preten...

C# Returning object from Array leaves pointer to Array item

I have a List<T> and I do the following: var myObj = List[2]; //Return object at position 2 myObj.Name = "fred"; //If you look at List[2] its name has changed to fred I tried the following but it still updates the item in the List var newObj = new MyObj(); var myObj = List[2]; //Return object at position 2 newObj = myObj; newObj.N...

How can I display a pointer address in C#?

I've not done any pointers since I've been programming in C# - and my C++ days were long ago. I thought I should refresh my knowledge and was just playing around with them because of another question on here. I understand them all okay, but I can't figure out how to write the pointer's address to the console... char c = 'c'; char d = ...

C++ Trouble with operator code inheritage: am I require to copy same code for all derived classes?

I'd like to write a group of class D_I (aka I=1,2,... just I mean '_I' to be class proper name, not integer) which handle some (boolean, for example) operations F with same meaning for all classes. But also I want to operate with "sums" of object of such classes, different classes of the group might be "added" together. Mentioned operati...

C pointers to functions

I am working on a program that sorts its input lines alphabetically/numericaly depending on the arguments passed to main. And this is the follow-up exercise: Add a field-handling capability, so sorting may be done on fields within lines, each field sorted according to an independent set of options. (The index for this book was sorted wi...

dynamic array IN struct, C

I have looked around but have been unable to find a solution to what must be a well asked question. Here is the code I have: #include <stdlib.h> struct my_struct { int n; char s[] }; int main() { struct my_struct ms; ms.s = malloc(sizeof(char*)*50); } and here is the error gcc gives me: error: invalid use of flexibl...

PHP Unset via References

I have been reading the PHP manual about references and something is confusing me. It says that references are not pointers to memory addresses but rather... Instead, they are symbol table aliases. Isn't this essentially a pointer if the reference points to the symbol table entry which then points to a memory address? Edit: So...

Best Way To Marshal A Pointer of Array of Struct

I'm calling functions from C++ that returns a pointer to an array of struct and I'm having problems since I'm new to this operation/implementation. My C++ codes: // My C++ Structs typedef struct _MainData { double dCount; DataS1 *DS1; int iCount1; DataS2 *DS2; int iCount2; }MainData; typedef struct _DataS1 { ...

Ways To Marshal A Pointer of Array of Struct

I'm calling functions from C++ that returns a pointer to an array of struct and I'm having problems since I'm new to this operation/implementation. My C++ codes: // My C++ Structs typedef struct _MainData { double dCount; DataS1 *DS1; int iCount1; DataS2 *DS2; int iCount2; }MainData...

C++ - Deleting a vector element that is referenced by a pointer

Hi all! Well, I don't know if it is possible, but the thing would be: struct stPiece { /* some stuff */ stPiece *mother; // pointer to the piece that created this one }; vector<stPiece> pieces; Is it possible to erase the piece referenced by 'mother' from pieces, having just that pointer as a reference? How? Would it mess with t...

Python equivalent of pointers

in python everything works by reference: >>> a = 1 >>> d = {'a':a} >>> d['a'] 1 >>> a = 2 >>> d['a'] 1 i want something like this >>> a = 1 >>> d = {'a':magical pointer to a} >>> d['a'] 1 >>> a = 2 >>> d['a'] 2 what would you substitute for 'magical pointer to a' so that python would output what i want i would appreciate general s...

Effect of placement of deference operator vs whitespace in C

Possible Duplicates: what is the difference between int i and int i? what is the difference between const int*, const int * const, int const * What is the difference between char* getInput(); and char *getInput(); ...

What's the Point of (NSError**)error?

Example: The -save: method of NSManagedObjectContext is declared like this: - (BOOL)save:(NSError **)error Since NSError is already an class, and passing an pointer would actually have the effect of modifying this object inside implementation of -save:, where's the point of passing an pointer to an pointer here? What's the advantage /...

Compact pointer notation with doubles

Quick question. When you are accessing a character array, I know you can set the pointer to the first element in the array, and use a while look and do something like while (*ptr != '\0') { do something } Now is there a double or int equivalent? #define ARRAY_SIZE 10 double someArray[ARRAY_SIZE] = {0}; double *ptr = someArray;...

C++: how to prevent destructing of objects constructed in argument?

I have a questing around such staff. There is a class A which has a object of type class B as it's member. Since I'd like B to be a base class of group of other classes I need to use pointer or reference to the object, not it's copy, to use virtual methods of B inside A properly. But when I write such code class B {public: B(in...