[net.sources.bugs] Call of non-function

ptraynor@bbnccv.UUCP (Patrick Traynor) (12/17/85)

While trying to compile some source code that I got over the net, my compiler
tripped over this line:

cmd->c_func(args, arg1, arg2, got1, got2);

In fact, at several points in the code, similar lines made the compiler throw
up.  The error was 'call of non-function'.  I understand what the code is
trying to do (although I've never tried it before), but since this compiler
cannot handle it, is there any simple way to rewrite this into more basic
code?

-- pat traynor --

arpa-- ptraynor at bbnccv
uucp-- ...harvard!bbnccv!ptraynor

john@frog.UUCP (John Woods, Software) (12/19/85)

>While trying to compile some source code that I got over the net, my compiler
>tripped over this line:
> 
>cmd->c_func(args, arg1, arg2, got1, got2);
> 
>In fact, at several points in the code, similar lines made the compiler throw
>up.  The error was 'call of non-function'.

Change the line to read

( * cmd->c_func ) (args, arg1, arg2, got1, got2);

Some compilers accept the shortcut (since its meaning is obvious), some don't.

--
John Woods, Charles River Data Systems, Framingham MA, (617) 626-1101
...!decvax!frog!john, ...!mit-eddie!jfw, jfw%mit-ccc@MIT-XX.ARPA

Out of my way, I'm a scientist!
	War of the Worlds

itkin@luke.UUCP (Steven List) (12/20/85)

In article <1155@bbnccv.UUCP> ptraynor@bbnccv.UUCP (Patrick Traynor) writes:
>While trying to compile some source code that I got over the net, my compiler
>tripped over this line:
>
>cmd->c_func(args, arg1, arg2, got1, got2);
>
>In fact, at several points in the code, similar lines made the compiler throw
>up.  The error was 'call of non-function'.

I am making a couple of assumptions: cmd is a pointer to a structure AND
that structure contains an element of the form:

	int (*c_func)();

If that is so, you've just run into something I've just finished
wrestling with.  The proper invocation of the function is:

	(*cmd->c_func)(args, arg1, arg2, got1, got2);

It is important to remember that the structure element is "a pointer to
a function returning an integer".  Thus you must use the contents of
that element, not the element, to invoke the function.  The parentheses
assure the proper evaluation of the statement (I tried it without and
got the wrong result - it tries to take the contents of the return from
the function or something).

If anyone else can clarify this further, please do so.
-- 
***
*  Steven List @ Benetics Corporation, Mt. View, CA
*  Just part of the stock at "Uncle Bene's Farm"
*  {cdp,engfocus,greipa,idi,oliveb,plx,sun,tolerant}!bene!luke!itkin
***

faustus@cad.UUCP (Wayne A. Christopher) (12/21/85)

> While trying to compile some source code that I got over the net, my compiler
> tripped over this line:
> 
> cmd->c_func(args, arg1, arg2, got1, got2);

You want "(*cmd->c_func) (args ...)". You can call a function, but you can't
call a pointer to a function... Most compilers will figure out what you
mean and do it anyway, but...

	Wayne