[net.micro.amiga] Lattice 3.02 Question

sdk@zeus.cs.ucla.edu (Scott D Kalter) (08/01/86)

I am having difficulty with the old 3.02 version of Lattice.  I was
hoping that someone could either point out that I am making a mistake
or that there really is a major bug in the compiler.

The problem I am having is using a pointer to a function, for instance:

foo() {
 printf("Hi\n"); }


bar() {
 int (*funptr)();   /* I believe this is the correct declaration */

 funptr = foo;      /* this line compiles without error */
 funptr();          /* this line generates an ERROR so no quad file is made */
}


The error generated is:
  
15  The identifier preceding the ( function call operator was
    not implicitly or explicitly declared as a function.


I checked some old code I had written on a UNIX VAX that used function
pointers and it looked much like the above.  I don't understand why
this doesn't work and I can't find any way to force it to work.

If someone recognizes this as a known compiler bug; do you know if this
is corrected in version 3.03 or the beta test 3.04 version?

Thanks for the help,
Scott Kalter

cjp@vax135.UUCP (Charles Poirier) (08/05/86)

In article <308@curly.ucla-cs.ARPA> sdk@zeus.UUCP (Scott D Kalter) writes:
>The problem I am having is using a pointer to a function, for instance:
>foo() {
> printf("Hi\n"); }
>bar() {
> int (*funptr)();   /* I believe this is the correct declaration */
> funptr = foo;      /* this line compiles without error */
> funptr();          /* this line generates an ERROR so no quad file is made */
>}

I can't speak to Lattice, but in standard C you have declared a pointer
to a function and assigned to it the address of a function, so use its
contents like any other pointer:

  (*funptr)();		/* this should compile */

jat@blnt1.UUCP (08/06/86)

In article <308@curly.ucla-cs.ARPA> sdk@zeus.UUCP (Scott D Kalter) writes:
>bar() {
> int (*funptr)();   /* I believe this is the correct declaration */
>
> funptr = foo;      /* this line compiles without error */
> funptr();          /* this line generates an ERROR so no quad file is made */
>}

The correct syntax for calling a function through a pointer is:

bar()
{
	int	(*funptr)();

	funptr=foo;
	(*funptr)();
}

funptr is a pointer to a function returning integer, so *funptr is a function
returning integer.  The parentheses are necessary because () binds more
tightly that does *.

John Tamplin					Blount Brothers Corporation
akgua!blnt1!jat					2511 Fairlane Drive
205/244-6231					Montgomery, AL  36116