storm@cs.mcgill.ca (Marc WANDSCHNEIDER) (05/26/91)
[ANSI C stuff] Why does the following: #include<stdio.h> float testfloat (void); void main(void) { float f; f = testfloat; printf("%7.3f\n", f); } float testfloat (void) { return 1.234; } Give me an ILLEGAL USE OF FLOATING POINT error...? ./*- -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storm@cs.mcgill.ca McGill University It's 11pm, do YOU Marc Wandschneider Montreal, CANADA know what time it is? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mrhoten@neon.Stanford.EDU (Matthew Paul Rhoten) (05/26/91)
In article <1991May25.213301.13765@cs.mcgill.ca> storm@cs.mcgill.ca (Marc Wandschneider) writes: >#include<stdio.h> >float testfloat (void); >[...] > f = testfloat; >[...] The problem is that parentheses are needed in a call to a function with a void argument list. When I try and compile the code above, I get "Illegal pointer arithmetic" or some such - because when I give the compiler the token "testfloat" it matches it with a pointer-type. I think the interpretation of the error is implementation-dependent. To call the function, simply include an empty set of parentheses after the function's name: f = testfloat(); This will work quite nicely. At least it did on my compiler. Hope this helps. -matt -- Matt Rhoten | PO Box 10031 | Standard disclaimers apply. mrhoten@cs.stanford.edu | Stanford, CA 94309 | (415) 497-2853 | veni vidi vomui
mouse@thunder.mcrcim.mcgill.edu (der Mouse) (05/30/91)
In article <1991May25.213301.13765@cs.mcgill.ca>, storm@cs.mcgill.ca (Marc WANDSCHNEIDER) writes: > Why does the following: [abstracted to relevant piece -Mouse] > float testfloat (void); [...] > float f; > f = testfloat; > Give me an ILLEGAL USE OF FLOATING POINT error...? Misfeature in your compiler. It should give you a message about pointer to function not being assignment compatible with float, 'cuz that's what what you've written is trying to do: set f to a pointer (to testfloat). der Mouse old: mcgill-vision!mouse new: mouse@larry.mcrcim.mcgill.edu