Calling multiple functions in a mac

William E. Davidsen Jr davidsen at steinmetz.ge.com
Sat Nov 12 05:55:30 AEST 1988


In article <44200018 at uicsrd.csrd.uiuc.edu> mcdaniel at uicsrd.csrd.uiuc.edu writes:

| A better definition is
| >> #define FOO()        foo1(), foo2(), foo3(), foo4()
| because it can be used in expressions.  However, you should use
| parentheses around macro text!  Consider
| 	bar(FOO())
| You expect bar() to be called with one argument, the value of foo4(),
| but instead bar() is called with 4 arguments.  (Lint catches most
| errors of this kind, which means most programmers will never notice
| this error until it causes the program to core dump.  8-( )
| 
| In general, when you write macros that evaluate to expressions, you
| should parenthesize the result, as above.

Somewhere the "as above" with correct parens seems to have gotten lost.
I'm sure what you meant was to state the example:
    #define FOO()        (foo1(), foo2(), foo3(), foo4())
as you explain in your text. I'm afraid that some readers may look at
the example and miss your points about macros in procedure calls, etc.

| 
| By the way, you should also parenthesize all uses of macro arguments.
| Consider
| 	#define two_it(x) (2*x)
| The whole thing is parenthesized, which is as suggested above.
| However, if it is called as "two_it(x+y)", this call becomes
| "(2*x+y)", which is probably NOT what you expected.
| 	#define two_it(x) (2*(x))
| works better.
| 
| -- 
| Tim, the Bizarre and Oddly-Dressed Enchanter
| Center for Supercomputing Research and Development
| at the University of Illinoid at Urbana-Champaign
| 
| Internet, BITNET:  mcdaniel at uicsrd.csrd.uiuc.edu
| UUCP:    {uunet,convex,pur-ee}!uiucuxc!uicsrd!mcdaniel
| ARPANET: mcdaniel%uicsrd at uxc.cso.uiuc.edu
| CSNET:   mcdaniel%uicsrd at uiuc.csnet
| DECnet?: GARCON::"mcdaniel at uicsrd.csrd.uiuc.edu"


-- 
	bill davidsen		(wedu at ge-crd.arpa)
  {uunet | philabs}!steinmetz!crdos1!davidsen
"Stupidity, like virtue, is its own reward" -me



More information about the Comp.lang.c mailing list