Article View: gnu.g++
Article #257Problem in pointers to function??
From: c60c-2ca
Date: Sat, 17 Mar 1990 21:18
Date: Sat, 17 Mar 1990 21:18
46 lines
1516 bytes
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
Technical Details
Message-ID:
<1990Mar17.211844.17043@agate.berkeley.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!ames!decwrl!shelby!agate!WEB.berkeley.edu!c60c-2caShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!ames!decwrl!shelby!agate!WEB.berkeley.edu!c60c-2ca From: c60c-2ca@WEB.berkeley.edu Newsgroups: gnu.g++,gnu.g++.bug,comp.lang.c++ Subject: Problem in pointers to function?? Message-ID: <1990Mar17.211844.17043@agate.berkeley.edu> Date: 17 Mar 90 21:18:44 GMT Sender: usenet@agate.berkeley.edu (USENET Administrator;;;;ZU44) Reply-To: c60c-2ca@WEB.berkeley.edu Distribution: usa Organization: University of California, Berkeley Lines: 46