[comp.lang.c++] Automatic variables of type pointer to function?

schwarze@isaak.uucp (Jochen Schwarze) (08/12/89)

Hello!

I just noticed, that it is obviously not possible to declare an
automatic variable of type pointer to function explicitly without
using a typedef. All other cases, both global and local static, and
even automatic declarations using a typedef work as expected.

Look at the following:


    int func() { return 0; }

    typedef int (*PFI)();

    int (*global_explicit)()    = &func;
    PFI global_typedef          = &func;

    main()
    {
	static PFI static_typedef       = &func;
	static int (*static_explicit)() = &func;

	PFI auto_typedef                = &func;
	int (*auto_explicit)()          = &func;    // error
    }


Although all of the above declarations with initializations seem to
be valid, both AT&T cfront 1.2 and g++ 1.35.0 complain about the
last declaration:

    cfront: error: auto_explicit is undefined
    g++: `auto_explicit' was not declared

What's wrong about the above code? What am I missing?
Or are the compliers the ones to blame?
Jochen Schwarze, ISA GmbH, Stuttgart, West Germany

UUCP:   schwarze@isaak.uucp
BITNET: schwarze%isaak.uucp@unido.bitnet

jeffa@hpmwtd.HP.COM (Jeff Aguilera) (08/19/89)

> 
> Look at the following:
> 
> 
>     int func() { return 0; }
> 
>     typedef int (*PFI)();
> 
>     int (*global_explicit)()    = &func;
>     PFI global_typedef          = &func;
> 
>     main()
>     {
> 	static PFI static_typedef       = &func;
> 	static int (*static_explicit)() = &func;
> 
> 	PFI auto_typedef                = &func;
> 	int (*auto_explicit)()          = &func;    // error
>     }
> 
> 
> Although all of the above declarations with initializations seem to
> be valid, both AT&T cfront 1.2 and g++ 1.35.0 complain about the
> last declaration:
> 
>     cfront: error: auto_explicit is undefined
>     g++: `auto_explicit' was not declared
> 
> What's wrong about the above code? What am I missing?
> Or are the compliers the ones to blame?
> Jochen Schwarze, ISA GmbH, Stuttgart, West Germany

Works fine on my HP/350 using AT&T C++ 2.0.  The regular HP-UX cc compiler
complains about "& before array or function".

paul@gill.UUCP (Paul Nordstrom) (08/21/89)

In article <1520001@hpmwjaa.HP.COM>, jeffa@hpmwtd.HP.COM (Jeff Aguilera) writes:
> > 
.
.	 several function definitions
.

> > 
> > 	int (*auto_explicit)()          = &func;    // error
> > 
> > Although all of the above declarations with initializations seem to
> > be valid, both AT&T cfront 1.2 and g++ 1.35.0 complain about the
> > last declaration:
> > 
> >     cfront: error: auto_explicit is undefined
> >     g++: `auto_explicit' was not declared
> > 
> > What's wrong about the above code? What am I missing?
> > Or are the compliers the ones to blame?
> > Jochen Schwarze, ISA GmbH, Stuttgart, West Germany
> 
> Works fine on my HP/350 using AT&T C++ 2.0.  The regular HP-UX cc compiler
> complains about "& before array or function".


Also works fine on my Sun 3/60 with Oregon C++ ver 1.2Ag.  Since the
original code did not include any executable code, I didn't test to
see if the code generated was or was not correct.



Paul Nordstrom
Gill & Co., L.P.
uunet!gill!paul

-- 
Paul Nordstrom
Gill & Co., L.P.
uunet!gill!paul