/*-=-=-=-=-=-=-=-=-=-=-=- RCCL/RCI Notice of Copyright -=-=-=-=-=-=-=-=-=-=-*
 *									    *
 *	Copyright (C) 1991 by John E. Lloyd.				    *
 *									    *
 *	Information on copyright permissions, as well as a complete	    *
 *	disclaimer of warranty, is given in the file COPYRIGHT.		    *
 *									    *
 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
#ifndef _ASSIGNMEM_H_
#define _ASSIGNMEM_H_
/*---------------------------------------------------------------------------
 *
 * DESCRIPTION:	Macros for assigning chunks of memory out of a 
 *		memory pool while preserving the required alignments.
 *
 * AUTHOR/DATE: John Lloyd, Fall 1989
 *
 * MODIFICATION HISTORY:
 *
 *--------------------------------------------------------------------------*/

#include "../h/cdefs.h"

#if vax
#define ALIGN 	int	/* could use char, but this checks the code out! */  
#define INT_PTR	int	/* an 'int' we can cast pointers to */
#else
#define ALIGN	double	/* one of the safer bets ... */
#define INT_PTR	long
#endif

/* Align the indicated size */
#define ALIGN_SIZE(size)	\
	((((size)+sizeof(ALIGN)-1)/sizeof(ALIGN))*sizeof(ALIGN))

/* Align the indicated memory pointer. 'mem' is assumed to be char* eqiv. */
#define ALIGN_MEM(mem)		\
	((char*)ALIGN_SIZE((INT_PTR)(mem)))

/* Assign x from the mem, and increment by an aligned size. (mem) must be
   of type "char *" */
#define ASSIGN_MEM(x,type,size,mem) \
	((x) = (type)(mem), (mem) += ALIGN_SIZE(size))

#endif
