pointers

Type casting, easy question for people good at C

Hello, i have a library which i have to pass (char **)&return_string to the function hci_scan as seen in this excerpt: char return_string[250]; int num_hosts; if ((num_hosts = hci_scan((char **) & return_string, 0x03)) > 0) { //case where one or more devices are found... } else { //case where zero devices are found... } afte...

Point and Line class in c++?

I'm learning C++ (and programming in general) and I'm trying to make both a Point class and a Line class. A line should be composed of 2 point objects. Can the C++ gurus look over my work and tell me if this is how you should appropriately use pointers, references and classes? class Point { private: int x, y; public: ...

Passing and storing pointers to immutable types and strings in C#

Is there a way to store a pointer to immutable types like strings in C#? How can execute: Instance1.SomeFunction(out MyString); ,and store a pointer to MyString inside of Instance1? ...

Possible memory leak?

Okay, so I have two classes, call them A and B--in that order in the code. Class B instantiates class A as an array, and class B also has an error message char* variable, which class A must set in the event of an error. I created a third class with a pure virtual function to set the errorMessage variable in B, then made B a child of that...

Passing Unmanaged pointers in C++/CLI

I'm creating a C++/CLI wrapper DLL that depends on numerous C++ static libraries. Some of the function calls expect unmanaged pointers to be passed in. How do i pass them properly? Also, other functions expect a "this pointer" to be passed in as a void*. What's the right way to pass "this"? Here's my class definition... public ref cla...

C : reverse a string in place. I used the prog answered in an earlier question. It compiles ok but crashes with segmenation fault

I call the function provided by Chris Conway (http://stackoverflow.com/questions/198199/how-do-you-reverse-a-string-in-place-in-c-or-c) from main (C code). When I run this program using cygwin, program crashes when it is in while loop (commented the lines where it breaks). Could you please explain what is going wrong here. Thanks #inclu...

javascript pointer function

Hi, if I have: function init(t,y,u) { alert(t + " " + y + " " + u); } // String.prototype.add = init(5, 6, 7); // 1) // window.onload = init(5,6,7); // 2) in the 1) init will be executed and then it pointer assegned to String.prototype.add but in the 2) the function is only executed one time... but why not two times also whe...

Why is it allowed to return unsafe pointers from within a function?

I've recently seen a couple of open source projects that actually do this; return an unsafe pointer from a function such as: "int* input = this.someIterator.GetUnsafePtr()". From my understanding this has to be completely wrong. Unsafe pointers can only be obtained through 'fixed' statements and certainly those returned from within a f...

What is the purpose of the frame pointer?

I'm a beginner in assembly language and have noticed that the x86 code emitted by compilers usually keeps the frame pointer around even in release/optimized mode, when it could use the EBP register for something else. I undertand why the frame pointer might make code easier to debug, and might be necessary if alloca() is called within a...

Why do I have to write *myPointerVar only SOMETIMES in Objective-C?

That's an issue I still don't understand. Sometimes I have to write: NSString* myVariable; myVariable = @"Hey!"; Then, for example I define a Structure "DemoStruct" and get an Variable that uses it. Lets say I have a Structure that has x and y vars from type double. I want to pass this var to a method which then manipulates my var, ...

What does the Asterisk * mean in Objective-C?

Is it true, that the Asterisk always means "Hey, that is a pointer!" And an Pointer always holds an memory adress? (Yes I know for the exception that a * is used for math operation) For Example: NSString* myString; or SomeClass* thatClass; or (*somePointerToAStruct).myStructComponent = 5; I feel that there is more I need to k...

Should you use pointers (unsafe code) in C#?

Should you use pointers in your C# code? What are the benefits? Is it recommend by The Man (Microsoft)? ...

calling a callback from a thread using function pointers

Hello, c program compiler gcc I have 3 files. main.c stop_watch.h and stop_watch.c This program does work. I call start_stopwatch. And it will callback in main.c timeout_cb() after the time has expired. I also run this in a seperate thread, as I don't want to block in main, as I will have other code I need to run. 1) The seconds in g...

c# Matrix of pictureBox

Hi! I'm developing a puzzle game for windows mobile. The objetive is to split an image in nine parts and rearrage them to obtain the original image. These split images are put on pictureBoxes and these pictureBoxes are redistributed in a matrix of 3X3 cells. The user move this cells to arrange them in the correct position (it's a puzzl...

Assigning to const int *

void main() { const int * a; *a = 5; } gcc error : assignment of read only location. so, how to assign to *a, without using another variable? and what could be a use of a declaration like above? ...

Using Pointers in Delphi

I have been developing for some time now, and I have not used pointers in my development so far. So what are the benefits of pointers? Does an application run faster or uses fewer resources? Because I am sure that pointers are important, can you “point” me to some articles, basic but good to start using pointers in Delphi? Google gives...

C++: difference between ampersand "&" and asterisk "*" in function/method declaration?

Is there some kind of subtle difference between those: void a1(float &b) { b=1; }; a1(b); and void a1(float *b) { (*b)=1; }; a1(&b); ? They both do the same (or so it seems from main() ), but the first one is obviously shorter, however most of the code I see uses second notation. Is there a difference? Maybe in case it's s...

Where exactly do function pointers point?

Given that all the primitive data types and objects have memory allocated, it is intuitively easy to imagine the pointers to these types. But where exactly do function pointers point to? Given that instructions are converted into machine code and reside in memory, should we consider they point to the memory location corresponding to the...

What is the difference between passing by reference in Java and passing a pointer in C?

I have been studying Java for a few months and am now starting to learn C. I am a little confused, I was under the impression that passing an object by reference and passing a pointer to that object were the same thing: I thought the difference was that in Java all passing of objects is done with pointers automatically, where as in C o...

Pointer mysteriously resetting to NULL

Hi everyone, I'm working on a game and I'm currently working on the part that handles input. Three classes are involved here, there's the ProjectInstance class which starts the level and stuff, there's a GameController which will handle the input, and a PlayerEntity which will be influenced by the controls as determined by the GameContr...