kjones@talos.UUCP (Kyle Jones) (03/07/89)
Reply-to: kjones@talos.UUCP (Kyle Jones)
Anyone know why vcc(1) gripes about pointers to functions being used
as functions. Example:
main()
{
int atoi();
int (*ascii_to_integer)() = atoi;
ascii_to_integer("3");
}
Compiling this program gives
"bug.c", line 6: %E-NOTFUNCTION, Function-valued expression not found.
"bug.c", line 7: %I-NOBJECT, No object file produced.
"bug.c", line 7: %I-SUMMARY, Completed with 1 error(s), 0 warning(s), and
1 informational messages.
As far as I know K&R (1st edition) and the pANS allow this. I know
I've been using it for years without problems. What's going on here?
bph@buengc.BU.EDU (Blair P. Houghton) (03/22/89)
Reply-to: bph@buengc.BU.EDU (Blair P. Houghton) In article <85725@felix.UUCP> kjones@talos.UUCP (Kyle Jones) writes: >Reply-to: kjones@talos.UUCP (Kyle Jones) > >"bug.c", line 6: %E-NOTFUNCTION, Function-valued expression not found. "not found" ? What does _that_ mean? --Blair
pinkas@hobbit.UUCP (Israel Pinkas ~) (03/22/89)
Reply-to: pinkas@hobbit.UUCP (Israel Pinkas ~) In article <85725@felix.UUCP> kjones@talos.UUCP (Kyle Jones) writes: > Anyone know why vcc(1) gripes about pointers to functions being used > as functions. Example: > > main() > { > int atoi(); > int (*ascii_to_integer)() = atoi; > > ascii_to_integer("3"); > } > > Compiling this program gives > > "bug.c", line 6: %E-NOTFUNCTION, Function-valued expression not found. > > "bug.c", line 7: %I-NOBJECT, No object file produced. > > "bug.c", line 7: %I-SUMMARY, Completed with 1 error(s), 0 warning(s), and > 1 informational messages. > > As far as I know K&R (1st edition) and the pANS allow this. I know > I've been using it for years without problems. What's going on here? Because it is wrong. See K&R, 1st edition, pg 114-117. They present a sort routine for strings which takes a comparison and exchange function. They state that with the declaration int (*comp)(), comp is a pointer to a function returning int. *comp is the function, and (*comp)(<args>) is the proper call. What they doi state is that when passing comp to the sort function, the name of the function is sufficient (i.e. the & is optional). They reason for this is that the compiler can determine that the identifier is a function, and functions are always passed by address (like arrays). I don't have a copy of the dpAns draft to check what they say about this. -Israel Pinkas -- -------------------------------------- Disclaimer: The above are my personal opinions, and in no way represent the opinions of Intel Corporation. In no way should the above be taken to be a statement of Intel. UUCP: {amdcad,decwrl,hplabs,oliveb,pur-ee,qantel}!intelca!mipos3!cadev4!pinkas ARPA: pinkas%cadev4.intel.com@relay.cs.net CSNET: pinkas@cadev4.intel.com
naftoli@aecom.yu.edu (Robert N. Berlinger) (03/23/89)
Reply-to: naftoli@aecom.yu.edu (Robert N. Berlinger) In article <85725@felix.UUCP>, kjones@talos.UUCP (Kyle Jones) writes: > Anyone know why vcc(1) gripes about pointers to functions being used > as functions. Example: > main() > { > int atoi(); > int (*ascii_to_integer)() = atoi; > > ascii_to_integer("3"); > } The function call should be (*ascii_to_integer)("3"); K&R has an example, check out page 116, 1st edition, or page 120, 2nd edition. Robert -- Robert N. Berlinger |Domain: naftoli@aecom.yu.edu Supervisor of Systems Support |UUCP: {uunet,philabs,phri}!aecom!naftoli Scientific Computing Center |CompuServe: 73047,741 GEnie: R.Berlinger Albert Einstein College of Medicine |Pan: berlinger