pointers and functions

This is a discussion on pointers and functions within the C++ Programming forums, part of the General Programming Boards category; Hello..
I have some program's source that I do not fully understand.
Could someone please help me to explain/understand how ...

Many of the Windows API functions require a pointer to some data as parameter where they store some result. If you pass 0 or an uninitialized pointer they fail or crash.
Guess you are talking about the lpCompletionKey parameter of GetQueuedCompletionStatus.
you have to do something like this

EDIT: I wonder why you want to pass a reference to a pointer. GetQueuedCompletionStatus won't change the pointer it will only dereference that pointer that you pass and store some result at this location. That WIN API functions are simple C API's, they don't understand references. If WIN API-functions want references to pointers then the parameters are pointers to pointers.
Kurt

Since when its unsigned long compl a pointer?
Is it better to use ULONG_PTR instead of unsigned long?

You posted this code :

Code:

someclass *sc_p = 0;
somefunction(sc_p);

The * makes sc_p a pointer to "someclass" types. When you define a pointer, no memory is automatically allocated for the variable it points to (because you might want it to point to something which already exists!)

You're probably looking to declare something on the stack and then pass a reference to it... In which case you need to do :

The main difference is that it's easier to use the first version incorrectly. On the other hand, some people (including Bjarne Stroustrup) prefer the pointer for parameters that get changed because the additional & at the function call site makes it clear that the value might be changed, without having to look at the parameter types of the function.

some people (including Bjarne Stroustrup) prefer the pointer for parameters that get changed because the additional & at the function call site makes it clear that the value might be changed, without having to look at the parameter types of the function.