[comp.lang.c] Returning a pointer to a function

magnuson@skyler.mavd.honeywell.com (Randy Magnuson - Honeywell Inc.) (03/25/91)

I am writing an application that needs a function that returns a pointer to a
function (which returns an int).  Can anyone send me an example of how to
declare such a function?
-- 
Randy R. Magnuson
magnuson@skyler.mavd.honeywell.com  (612-542-5052)

ta@swsrv1.uucp (Tom Armistead) (03/26/91)

In article <1991Mar25.094620.70@skyler.mavd.honeywell.com> magnuson@skyler.mavd.honeywell.com (Randy Magnuson - Honeywell Inc.) writes:
>I am writing an application that needs a function that returns a pointer to a
>function (which returns an int).  Can anyone send me an example of how to
>declare such a function?

There is a program called cdecl in the Unix archives that you need to get. It
will take an english description of what you want and give you a C declaration
or vice-versa.

Ex.
   cdecl> declare func as function returning pointer to function returning int
   cdecl> int (*func())()

Where the 1st line is what you type in and the second is cdecl's response...

The stuff is in Volume14: cdecl2.1.Z and cdecl2.2.Z

Tom
-- 
Tom Armistead - Software Services - 2918 Dukeswood Dr. - Garland, Tx  75040
===========================================================================
{void,egsner}!swsrv1!toma                           mic!ozdaltx!swsrv1!toma
{uunet,smu,ames}!sulaco!ozdaltx!swsrv1!toma

bierman@davidsys.com (03/28/91)

In article <1991Mar25.094620.70@skyler.mavd.honeywell.com>, magnuson@skyler.mavd.honeywell.com (Randy Magnuson - Honeywell Inc.) writes:
> I am writing an application that needs a function that returns a pointer to a
> function (which returns an int).  Can anyone send me an example of how to
> declare such a function?
> -- 
> Randy R. Magnuson
> magnuson@skyler.mavd.honeywell.com  (612-542-5052)

how about:

typedef   int   (*fnPT)();
fnPT	yourFunction() {....};

Andy Bierman
bierman@davidsys.com

browns@iccgcc.decnet.ab.com (Stan Brown) (03/29/91)

In article <1991Mar25.205433.9958@swsrv1.uucp>, ta@swsrv1.uucp (Tom Armistead) writes:
> In article <1991Mar25.094620.70@skyler.mavd.honeywell.com> magnuson@skyler.mavd.honeywell.com (Randy Magnuson - Honeywell Inc.) writes:
>>I am writing an application that needs a function that returns a pointer to a
>>function (which returns an int).  Can anyone send me an example of how to
>>declare such a function?
> 
> There is a program called cdecl in the Unix archives that you need to get. It
> will take an english description of what you want and give you a C declaration
> or vice-versa.
> 
> Ex.
>    cdecl> declare func as function returning pointer to function returning int
>    cdecl> int (*func())()
> 
> Where the 1st line is what you type in and the second is cdecl's response...
> 
> The stuff is in Volume14: cdecl2.1.Z and cdecl2.2.Z

Anything for those of us with no Unix access?  (MS-DOS and VAX/VMS)

My opinions are mine:  I don't speak for any other person or company.
                   email (until 91/4/30): browns@iccgcc.decnet.ab.com
Stan Brown, Oak Road Systems, Cleveland, Ohio, USA    +1 216 371 0043

gwyn@smoke.brl.mil (Doug Gwyn) (03/30/91)

In article <4032.27f30e01@iccgcc.decnet.ab.com> browns@iccgcc.decnet.ab.com (Stan Brown) writes:
>In article <1991Mar25.205433.9958@swsrv1.uucp>, ta@swsrv1.uucp (Tom Armistead) writes:
>> There is a program called cdecl in the Unix archives that you need to get. It
>Anything for those of us with no Unix access?  (MS-DOS and VAX/VMS)

Yeah -- you can find the source in K&R2 (5.12) for a simpler similar
program, and with a modest amount of work you should be able to fill
in the gaps.  Or, you could adapt the "cdecl" sources; there shouldn't
be any real dependencies on UNIX in that program.

browns@iccgcc.decnet.ab.com (Stan Brown) (04/01/91)

In article <15635@smoke.brl.mil>, gwyn@smoke.brl.mil (Doug Gwyn) writes:
> In article <4032.27f30e01@iccgcc.decnet.ab.com> browns@iccgcc.decnet.ab.com (Stan Brown) writes:
>>In article <1991Mar25.205433.9958@swsrv1.uucp>, ta@swsrv1.uucp (Tom Armistead) writes:
>>> There is a program called cdecl in the Unix archives that you need to get. It
>>Anything for those of us with no Unix access?  (MS-DOS and VAX/VMS)
> 
> Yeah -- you can find the source in K&R2 (5.12) for a simpler similar
> program, and with a modest amount of work you should be able to fill
> in the gaps.  Or, you could adapt the "cdecl" sources; there shouldn't
> be any real dependencies on UNIX in that program.

Sigh!

If the archives were plain-text source code it wouldn't be a problem.
But Unix executables won't run on MS-DOS or VAX/VMS as far as I know.
And programs in source code that have been tar'd or z'd or whatever 
require Unix-based utilities to unpack them.

My opinions are mine:  I don't speak for any other person or company.
                   email (until 91/4/30): browns@iccgcc.decnet.ab.com
Stan Brown, Oak Road Systems, Cleveland, Ohio, USA    +1 216 371 0043