[comp.os.msdos.apps] Windows and pointers as parameters

akm@geriatrix.cs.uoregon.edu (Anant Kartik Mithal) (03/23/91)

Hi,

a question about pointers as function parameters. Given that windows
can move code/data around in memory (I believe that is correct), is
it okay (or is it not okay) to pass pointers as the arguments to a
function? What I want to do is to have a function set the values of a
couple of variables (boring sort of stuff), but I am not sure that I
can pass the variables through pointers to the setting function. eg:

void CallerFunction ()
{
	int x, y;
	SetValue(&x, &y)
.
.
}

void SetValue(x, y)
int *x, *y;
{
	*x = 10;
	*y = 20;
}

thanks in advance,

kartik

-- 
Anant Kartik Mithal                                     akm@cs.uoregon.edu
Research Assistant, 					(503)346-4408 (msgs)
Department of Computer Science,                         (503)346-3989 (direct)
University of Oregon, Eugene, OR 97403-1202

richardh@hpopd.pwd.hp.com (Richard Hancock) (03/26/91)

/ hpopd:comp.os.msdos.apps / akm@geriatrix.cs.uoregon.edu (Anant Kartik Mithal) /  6:55 pm  Mar 22, 1991 /
Hi,

> a question about pointers as function parameters. Given that windows
> can move code/data around in memory (I believe that is correct), is
> it okay (or is it not okay) to pass pointers as the arguments to a
> function? What I want to do is to have a function set the values of a
> couple of variables (boring sort of stuff), but I am not sure that I
> can pass the variables through pointers to the setting function. eg:

You shouldn't ASSUME that your DS will never change (though I suspect
that in never will in protected mode). Therefore you shouldn't keep
hold of a far pointer to a variable in your DS across any call which
might cause your DS to move (eg. a GlobalAlloc() call).

Having said that, I seem to remember that Windows locks your DS when
it calls your WndProc.

Summary : only pass near pointers; if you do eventually need them as far
pointers simply cast them when you need to use them.

Richard.