🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by c60c-2ca Sat, 17 Mar 1990 21:18
Problem in pointers to function??
#257
Author: c60c-2ca
Date: Sat, 17 Mar 1990 21:18
46 lines
1516 bytes
	I discovered the following bug (or is it?) while trying to compile
the following program:

void print(void)
{
	;	// dummy statement
}

int main(void)
{
	void (*funcPointer)(void);	// This is line 8
	funcPointer = print;

	funcPointer();
	(*funcPointer)();

	return 0;
}

Here is what I got when I tried to compile it...

bug.c: In function int main ():
bug.c:8: `funcPointer' undeclared (first use this function)
bug.c:8: (Each undeclared identifier is reported only once
bug.c:8: for each function it appears in.)
bug.c:8: parse error before `)'


However, if I add the type definition:

	typedef (*PTR_TO_FUNCTION)(void);

And then replace line 8 with:

	PTR_TO_FUNCTION funcPointer;

The program compiles.  Is there something I am doing wrong?
By the way, the compiler I was using is g++ (version 1.37.1) on a SUN 
workstation.

Please email response to my account.  
Thanks.

Andrew Choi
Internet Address:  c60c-2ca@web.berkeley.edu or c186cd@cory.berkeley.edu
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads