/*
	xdstruct.c - saving and restoring structures from extended memory.

	Description:
		A structure is saved to and restored from a block of extended
		memory using a pointer to the structure and the sizeof function.

	Uses:
		xdata, root2xmem, xmem2root
*/

#use xmem.lib

struct point { unsigned int x; float y; };

struct point pt,*ptptr;

xdata xmemblock [10];

main()
{
int ptsize;

	printf("\nstructure { unsigned int; float; }\n");
	pt.x = 1;
	pt.y = 1.0;
	printf("\nstructure members:\t%d,\t%f\n",pt.x,pt.y);

	ptsize=sizeof(pt);
	printf("structure size in bytes:\t%d\n",ptsize);

	printf("\nsaving structure to xmem...\n");
	ptptr = &pt;
	root2xmem(ptptr,xmemblock,ptsize);

	pt.x = 2;
	pt.y = 2.0;
	printf("\nnew structure members:\t%d,\t%f\n",pt.x,pt.y);

	printf("\n\nretrieving structure from xmem...\n");
	xmem2root(xmemblock,ptptr,ptsize);
	printf("\noriginal structure members:\t%d,\t%f\n",ptptr->x,ptptr->y);
}
