Functions with union parameters

Doug Gwyn gwyn at brl-vgr.ARPA
Sat Apr 7 05:03:54 AEST 1984


I believe "lint" does warn about the non-portable struct/union kludges
in your examples.  However, if you were to use correct types for the
parameters in the first place, it would be perfectly portable (as I
believe Guy Harris has pointed out in another response).

A useful guideline is: with few exceptions, if one finds he is using
coercions (typecasts) heavily, he has chosen inappropriate data types.

It is true that some C implementations may have to resort to "thunks"
to pass struct/array parameters or function return values.  This can
be messy; for example, on PDP-11 UNIXes, one cannot use struct-valued
functions in the kernel since interrupts wreak havoc with the partially-
returned structs.  It is also usually much more efficient to pass
pointers to structs than the actual structs, as is well known.



More information about the Comp.lang.c mailing list