[comp.sys.mac.programmer] Returning Addresses from functions

kevin@crash.cts.com (Kevin Hill) (03/14/91)

 
I wish to create functions that return a pointer to a memory location.
Similar to malloc.  However, whenever the calling function is not in the
same file as the pointer returning function, the address returned is only
4 bytes long.  I.e. if the address was originally
 Actual                               Returned
 0x1D1DFFFF                           0x0000FFFF
 0x3F175432                           0x00005432
 
it seems that only 4 bytes are returning from the function when it is
another .c file.  HOWEVER, when the calling function and the function 
itself are in the same .c file, there is not a problem.. The addresses
are returned correctly...
  Any ideas??
 
 
I am using The latest version of Think C 3.xxx (Yes I know Think C 4.0 is
out, but I am a college student and $60 buys a lot of beer :)    )
 
Here is a copy of the function that is returning the address.
 
struct 	hub		{
				Point		point;
			struct hub		*next;
				};
typedef	struct	hub		Hub,	*HubPtr,	**HubHandle;
 
 
HubPtr	cur_bhub(hub,flag)
	HubPtr	hub;
	int		flag;
{
	static	HubPtr	beg_hub;
	
	if (flag != 0)
		beg_hub = NULL;
	if (hub != NULL)
		beg_hub = hub;
	return(beg_hub);
}
 
 Thank you in advance 
 -Kevin
 
 

wjb@tantalum.eds.com (Bill Biesty) (03/20/91)

In article <7984@crash.cts.com> kevin@crash.cts.com (Kevin Hill) writes:
->
-> 
->I wish to create functions that return a pointer to a memory location.
->Similar to malloc.  However, whenever the calling function is not in the
->same file as the pointer returning function, the address returned is only
->4 bytes long.  I.e. if the address was originally
-> Actual                               Returned
-> 0x1D1DFFFF                           0x0000FFFF
-> 0x3F175432                           0x00005432
-> 
->it seems that only 4 bytes are returning from the function when it is
->another .c file.  HOWEVER, when the calling function and the function 
->itself are in the same .c file, there is not a problem.. The addresses
->are returned correctly...
->  Any ideas??

Hmm.  If the function is not declared as returning a pointer in the file
it's called from then it's assumed to be returning an int.  This is a 
super obvious explanation and I don't have the reference to verify int and
pointer sizes.

Bill