In article <1992Dec30.184135.1963@organpipe.uug.arizona.edu>, dave@cs.arizona.edu (Dave Schaumann) writes:
|> It has come to me that C's mechanisms for parameter passing are less than
|> wonderful. For instance, in defining some data structure, my typical
|> stratagy is to create a .h file with the struct definition, appropriate
|> typedefs, and #defines for simple functions.
|>
|> The root of the problem is that I want to pretend that macros are really
|> in-line functions. However, "macro functions" display "call by reference"
|> behavior, while real functions have call by value behavior.
|>
|> One solution is to always pass pointers -- in effect, change the default
|> parameter behavior (for structs, anyway) to be call-by-reference.
After coding a whole bunch of system modules I would consider this:
No exported macros at all - use functions instead ...
Furthermore highly encapsulate thy data, not exporting any structures:
#ifdef MODULE_PRIVATE
typedef struct ModuleDataRec
{....
} ModuleDataRec, *ModulData;
#define SetMember(d, v) (*d).member = v;
#else
typedef void *ModulData;
void SetMember(ModulData d, int v);
#endif;
This technique was forced by using runtime libraries, where you can't ensure that anyone using your module will recompile with a new version (btw for me this would be a contradiction to rtl's) ...
For the VERY few uses where the above will lead into performance-troubles, grant them MODULE_PRIVATE, with all it's disadvantages ...
On performance: I think that on risc systems the calling overhead is no problem after all (on DEC Alpha, the first six parameters are passed through registers, and there's nearly no call frame to be built ...), under VAX-VMS (and on other systems doing lots on the stack) it can get a problem ...