🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #3670

Re: function pointers (in C)

#3670
From: Stan Brown
Date: Wed, 07 Oct 1992 10:45
29 lines
1671 bytes
In article <1992Oct5.222801.12917@u.washington.edu> goble@hardy.u.washington.edu (Brian Goble) writes:
>I want to be able to pass a function pointer to another function, have that
>function store the function pointer in a structure field, and later,
>call that function from the structure field.  The function pointer is to
>a function that returns an "int" and takes a "LPWORD" as it's only arg.
>
>A #define would be nice too...

So often MS-DOS questions are posted in comp.lang.c, it's novel to see a
C question in comp.os.msdos.programmer.

I don't know what you mean by "a #define would be nice"; typedefs are
the way to go for this.

The general principle if a typedef is to write a normal declaration that
looks the way you want, stick the word _typedef_ in front of it, and the
"variable" is the name of the new type.  Also for function pointers I
find it easiest to define a type for the function not the pointer.

Therefore:
     typedef int LPIFUNC(LPWORD);

A pointer to such a function would be 
     LPIFUNC *funcptr;
either independently as a variable or as a structure member or as a
function argument.
-- 
Stan Brown, Oak Road Systems                      brown@Ncoast.ORG
Cleveland, Ohio, USA
Technical Details
Message-ID: <Bvqz7x.I19@NCoast.ORG>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!ncoast!brown
References: <1992Oct5.222801.12917@u.washington.edu>

Show Full Headers
Complete Article Headers
Newsgroups: comp.os.msdos.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!ncoast!brown
From: brown@NCoast.ORG (Stan Brown)
Subject: Re: function pointers (in C)
Organization: Oak Road Systems, Cleveland Ohio USA
Date: Wed, 7 Oct 1992 10:45:31 GMT
Message-ID: <Bvqz7x.I19@NCoast.ORG>
References: <1992Oct5.222801.12917@u.washington.edu>
Lines: 29