pointers

What is double star?

So, I saw this: error:(NSError **)error in the apple doc's. Why two stars? What is the significance? ...

Correct way to use UIActionSheet Delegate? Pointers Mapped to identical Memory

I am using the actionSheet variable passed by actionSheet:didDismissWithButtonIndex: to compare the calling actionSheet to a list of UIActionSheet variables in my class. This seems to be the way the delegate method was designed to differentiate between events. - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(N...

How do I access an individual character from an array of strings in c?

Just trying to understand how to address a single character in an array of strings. Also, this of course will allow me to understand pointers to pointers subscripting in general. If I have char **a and I want to reach the 3rd character of the 2nd string, does this work: **((a+1)+2)? Seems like it should... ...

C#: Benefit of explicitly stating "unsafe" / compiler option

I understand pointers and the rare need to use them in C# code. My question is: what is the reasoning behind having to explicitly state "unsafe" in a block of code. Additionally, why must a compiler option be changed to allow "unsafe" code? Bottom Line: What in the CLR (or language specs) makes it so we can't just use pointers whenever ...

Returning the addresses of objects created outside the main() function.

I am trying to create a link list, but I am having trouble creating objects inside a function and assigning pointers to their addresses, since I believe they go out of scope when the function exits. Is this true? And, if so, how can I create an object outside the main and still use it? ...

What does this error mean: "error: expected specifier-qualifier-list before 'type_name'"?

I'm a bit new to working with c/c++, so sorry if this is a dumb question. I've been working on the Cell processor and I'm trying to create a struct that will hold an spe_context_ptr_t, which will be used within the thread to launch an spe context and will also hold a pointer to something else that will be passed to the spu context from w...

Initializing an array of pointers to pointers

This example works fine: static char *daytab[] = { "hello", "world" }; This doesn't: static char *daytab[] = { {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} }; The way I see it is that the first example creates an array that is filled with pointers to the tw...

How to create multiple objects in the same function but without overwriting each other?

I'm trying to create an object in a function, but I am running into the problem that variable names have to be defined at runtime. Is there something I can do like with arrays that allows ne to dynamically create a variable in a function and preferably give it a different name from the one created when the function was called last? ***I...

Pointer to a Pointer question

I have a class with a (non smart) pointer to an interface object (lets call it pInterface) and I am building a nested class which also needs access to that interface. I am going to get around this by passing the pointer to the interface into the constructor of the nested class like so: CNestedClass someClass( pInterface, ... ); Howeve...

Is there any reason to check for a NULL pointer before deleting ?

I see some legacy code checking for null before deleting the pointer. as like below if(NULL != pSomeObject)//any reason for checking for null { delete pSomeObject; pSomeObject = NULL;//any reason for assigning null } my compiler is vc6 pre-standard one though. ...

Is there a good way to perform WPF/C# object dereferencing, for garbage collection?

Application Background Our platform is a click-once WPF application. We have a "shell" that contains a navigation menu structure and it hosts our own custom "page" classes. When you navigate to a new page, we swap out the content of the shell (essentially). Problem So, I work for a company that is working on a extremely large softwar...

difference between a pointer and reference parameter?

Are these the same: int foo(bar* p) { return p->someInt(); } and int foo(bar& r) { return r.someInt(); } Ignore the null pointer potential. Are these two functions functionally identical no matter if someInt is virtual or if they are passed a bar or a subclass of bar? Does this slice anything: bar& ref = *ptr_to_bar; -cory ...

How do I create an array of pointers?

I am trying to create an array of pointers. These pointers will point to a Student object that I created. How do I do it? What I have now is: Student * db = new Student[5]; But each element in that array is the student object, not a pointer to the student object. Thanks. ...

NULL pointer with boost::shared_ptr?

What's the equivalent to the following: std::vector<Foo*> vec; vec.push_back(NULL); when dealing with boost::shared_ptr? Is it the following code? std::vector< boost::shared_ptr<Foo> > vec; vec.push_back(boost::shared_ptr<Foo>()); Note: I may push back a lot of such objects. Should I declare a global static nullPtr object somewhere...

C# unsafe value type array to byte array conversions

I use an extension method to convert float arrays into byte arrays: public static unsafe byte[] ToByteArray(this float[] floatArray, int count) { int arrayLength = floatArray.Length > count ? count : floatArray.Length; byte[] byteArray = new byte[4 * arrayLength]; fixed (float* floatPointer = floatArray) { fixed ...

Expose memory as read-only

In C can a function expose memory that it "manageds" at a lower level as readonly to those calling that function (exposing its address). return * const is not effective but I wondered if I was overlooking a programming tick? Thanks. const uint8_t * get_value(int index) { static uint8_t data[2] = {0, 0}; return (const uint8_t *)&data[i...

converting char** to char* or char

I have a old program in which some library function is used and i dont have that library. So I am writing that program using libraries of c++. In that old code some function is there which is called like this *string = newstrdup("Some string goes here"); the string variable is declared as char **string; What he may be doing in that f...

Overloading << operator C++ - Pointer to Class

class logger { .... }; logger& operator<<(logger& log, const std::string& str) { cout << "My Log: " << str << endl; return log; } logger log; log << "Lexicon Starting"; Works fine, but i would like to use a pointer to a class instance instead. i.e. logger * log = new log(); log << "Lexicon Starting"; Is this possible? If ...

Why do I have to use free on a pointer but not a normal declaration?

Why do I have to use free() when I declare a pointer such as: int *temp = (int*)malloc(sizeof(int)) *temp = 3; but not when I do: int temp = 3; ...

zero length arrays vs. pointers

EDIT: apparently some of this isn't allowed/has changed in various C standards. For my own hypothetical benefit, let's pretend we're using gcc test.c with no standard or warning options. In particular I'm looking at the under-the-hood specifics. I've added my current understanding. Am I right? char **c1; //Size for a pointer is al...