🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

3 total messages Started by Jonathan D. Becher Tue, 11 Oct 1988 21:45
G++ doesn't handle pointers to functions
#1495
Author: Jonathan D. Becher
Date: Tue, 11 Oct 1988 21:45
37 lines
1218 bytes
The following program compiles with gcc but not with g++.
It seems as if g++ doesn't understand formal parameters that
are pointers to functions.
If anyone can think of a way around this bug (or explain to me 
why it isn't one), please let me know.
I can't live without pointers to functions :->

Program:

#include <stdio.h>
doSomething()
{
    printf("I did\n");
}

doThis(int (*f)())
{
    f();
}

main()
{
    doThis(doSomething);
}

Compilation:

g++ version 1.25.0
/usr/local/lib/gcc-cpp+ -v -undef -D__GNU__ -D__GNUG__ -Dvax -Dunix t.cc /tmp/cc011037.cpp
/usr/local/lib/gcc-c++ /tmp/cc011037.cpp -quiet -dumpbase t.cc -noreg -version -o /tmp/cc011037.s
GNU C++ version 1.25.0 (vax) compiled by GNU C version 1.25.
t.cc:9: undeclared variable `f' (first use here)


=====
Jon Becher
becher@cs.duke.edu          -OR-           argosy!becher@decwrl.dec.com
Re: G++ doesn't handle pointers to functions
#1494
Author: Jonathan D. Becher
Date: Tue, 11 Oct 1988 22:18
24 lines
949 bytes
In article <68@armada.UUCP>, I write:
   > It seems as if g++ doesn't understand formal parameters that
   > are pointers to functions.

In my previous posting, you can get around this error by using a typedef.
For some reason, this:
   > doThis(int (*f)())
   > {
   >     f();
   > }
doesn't work but this does:
   typedef int (*ptrFunc)();
   doThis(ptrFunc f)
   {
       f();
   }

In any event, it's still a bug.
=====
Jon Becher
becher@cs.duke.edu          -OR-           argosy!becher@decwrl.dec.com

"I go to parties, some times until four.
 It's hard to leave when you can't find the door."
G++ doesn't handle pointers to functions
#1496
Author: Michael Tiemann
Date: Wed, 12 Oct 1988 00:25
32 lines
1772 bytes
   Date: 11 Oct 88 21:45:49 GMT
   From: armada!becher@decwrl.dec.com  (Jonathan D. Becher)
   Organization: I have no organization (look at my desk)
   Sender: bug-g++-request@prep.ai.mit.edu

   The following program compiles with gcc but not with g++.
   It seems as if g++ doesn't understand formal parameters that
   are pointers to functions.
   If anyone can think of a way around this bug (or explain to me 
   why it isn't one), please let me know.
   I can't live without pointers to functions :->

From your previous posting, it is clear that you already know that
using a typedef solves this problem.  By using a typedef, you save
compilation time (less declarator structure to grok).  If, however,
you are somehow alergic to using typedefs, one thing you can do is this:

  doThis(auto int (*f)())
  {
      f();
  }

This will (or should) then compile.  This is a bug in the C++
language.  I wish that the designers of C++ knew enough about LALR
parsing to have made their language LALR-parsable; unfortunately, they
did not.  I consider the AT&T solution (which also doesn't always work
for pointers to functions in parameter positions) of using heuristics
to help try to guide the parser unacceptable, and certainly something
which I would want to distribute, freely or otherwise.

Michael
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