[comp.lang.c] #define foo

phil@ux1.cso.uiuc.edu (02/02/90)

What about:

#define foo bar()
n = *foo();


You would get:

n = *bar()();


Which would be ok if bar() is defined as a function that returns a pointer
to a function returning a (typeof (n)).  Right?  Obscure?

--Phil Howard, KA9WGN--
<phil@ux1.cso.uiuc.edu>

chris@mimsy.umd.edu (Chris Torek) (02/02/90)

(The answer to the original question is `yes'.  Almost anything is legal
as replacement text, including unbalanced parentheses, for instance.)

(Incidentally, it is `ANSI', not `ANSII': ANSI = American National
Standards Institute.  The one with two `I's is ASCII: American Standard
Code for Information Interchange.)

In article <6200025@ux1.cso.uiuc.edu> phil@ux1.cso.uiuc.edu writes:
>What about:
>	#define foo bar()
>	n = *foo();
>You would get:
>	n = *bar()();
>Which would be ok if bar() is defined as a function that returns a pointer
>to a function returning a (typeof (n)).  Right?  Obscure?

It could be correct, but not as given here: the binding is such that this
is handled as

	  bar()			call bar
		()		call the function so located
	*			indirect

so bar() would have to return a pointer to a function returning a pointer
to a type compatible with variable `n'.  If `n' were `int', for instance:

	int *(*bar(int))(char *);
	int n;

	n = *bar(3)("hello world");

is legal.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@cs.umd.edu	Path:	uunet!mimsy!chris