Calling multiple functions in a macro.

Peter Rowell peter at thirdi.UUCP
Wed Nov 2 03:27:42 AEST 1988


In article <353 at marob.MASA.COM> daveh at marob.masa.com (Dave Hammond) writes:
>...
>2.
>#define FOO()	foo1(), foo2(), foo3(), foo4()
>...
>The second compiles, executes and lints correctly (on Xenix), but
>is it portable to string function calls in this manner?

What you have is an expression using the comma operator.  Expressions
are one of the basic statement types in C.  If this isn't portable
using a given C compiler, then it isn't a C compiler.

See K&R, pg 192, Appendix A, 7.15 "Comma operator"

One suggestion: wrap the whole thing in parens to prevent any possible
nasty side effects.

#define FOO()	(foo1(), foo2(), foo3(), foo4())

"... Comma comma comma come on, yeah yeah yeah..."
		    James Taylor
----------------------------------------------------------------------
Peter Rowell
Third Eye Software, Inc.		(415) 321-0967
Menlo Park, CA  94025			...!pyramid!thirdi!peter



More information about the Comp.lang.c mailing list