intro_pitfalls


	This help topic is intended to contain various programming
	pitfalls and their avoidance.  If you are aware of other
	topics that should be added here, please feel free to add
	them.  If you don't feel comfortable doing that, please
	contact Brian Hendricks (hendricks@fnal.gov), and he will
	be glad to help you.


	Packed strucutures:

	By default, modern compilers align structure members
	on certain memory boundaries rather than packing them
	byte by byte.  This may in some cases improve performance,
	but in cases where you are either receiving data from
	or sending data to certain services such as the database,
	Filesharing, or most network requests this may lead to
	a mismatch between the message data and the structure
	definition.  To override this default behavior, there
	is a a special compiler directive (__attribute__((packed)))
	which packs structure members as tightly as possible.
	You definitely need to use this directive when reading
	database or Filesharing information.

	typedef struct MY_STRUCT
	    {
		.
		.
		.
	    } __attribute__((packed)) MY_STRUCT;	// structure is now packed


	Special CLIB status values:

	Some CLIB routines and most DIO_xxx routines which access
	multiple devices return multipurpose status values.  In
	the case that there is an overall error, a simple ACNET
	error code is returned.  However, if some data accessed
	is handled successfully while others are not, the status
	value returned is a simple integer which indicates the
	number of values that were unsuccessfully accessed.  These
	routines should have an argument which contains an array
	of returned status values, one for each piece of data
	accessed.  So, if you receive an overall status that is
	a positive integer, you need to scan the array of individual
	status values to see which ones succeeded and which failed.
	If you are only interested in reporting the first error in
	the list, the routine error_in_list_c can be used to extract
	that information.

	char	units[NUM_DEVICES][LEN_DEV_UNITS];
	short	errors[NUM_DEVICES];
	int	status;
	int	list_id;
	int	same_time;
	int	values_per_device[NUM_DEVICES];

	status = dio_get_lst(&list_id,values,errors,units,&same_time,
			     values_per_device);
	if (status != OK)
	    {
	    if (status > 0)
	    status = error_in_list_c(status,NUM_DEVICES,errors);
	    return (status);
	    }