Crossfire Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CF: crossfire code directions.



On Wed, Aug 27, 1997 at 12:31:41PM -0800, Scott Wedel wrote:
> I suggest that CF make the changes to refer to object fields via macros/
> functions without worrying too much about the perf impact of the change.
> Though, if there are compiler option for various compilers that result
> in faster code then those should be made part of the Makefiles.

I can only second this. Priorities should be:
1. Clean, simple and safe code
2. Efficient code

The advantage of functions over function-like macros is that functions
support type checking, and there is no problem with arguments evaluated
twice. So the direction is clear now: use functions.

What I suggested yesterday was:

[I'll call the files attrib.h and attrib.c in this message. I don't know if
there are already files named like this in crossfire.]
----------------------------------------
/* attrib.h */
#ifndef __GNUC__
#define __inline__
#endif

__inline__ static void SET_SPEED (...

----------------------------------------

A more complex alternative (you have to provide prototypes, and there are
more #ifdefs) that can avoid duplication of the functions on systems that
do not support function inlining:

----------------------------------------
/* attrib.h */
#ifndef ATTRIB_H_INCLUDED
#define ATTRIB_H_INCLUDED

#ifdef INLINE_FUNCTIONS

#ifdef __GNUC__
#define CF_INLINE __inline__ static   /* gcc has __inline__ keyword */
#else
/* other compiler specific defines similar to the gcc support can be
inserted here */
#define CF_INLINE static   /* portable define */
#endif

/* this will provide static definitions of the functions */
#include "attrib.c"

#else /* #ifdef INLINE_FUNCTIONS */

void SET_SPEED (...);
...

#endif /* #ifdef INLINE_FUNCTIONS */

#endif
----------------------------------------
/* attrib.c */

#if defined(CF_INLINE) || ! defined (INLINE_FUNCTIONS)

#include ...
#include "attrib.h"
#include ...

#ifndef CF_INLINE
#define CF_INLINE extern
#endif

CF_INLINE void SET_SPEED (...)
{
	...
}

...

#undef CF_INLINE

#endif
----------------------------------------

Is the second alternative worth the effort?

--
Jan
[to unsubscribe etc., send mail to crossfire-request@ifi.uio.no]