home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!darwin.sura.net!spool.mu.edu!yale.edu!ira.uka.de!math.fu-berlin.de!cs.tu-berlin.de!jutta
- From: jutta@opal.cs.tu-berlin.de (Jutta Degener)
- Subject: Re: Pointer to Function Question
- Message-ID: <1992Dec15.153904.13231@cs.tu-berlin.de>
- Sender: news@cs.tu-berlin.de
- Organization: Techn. University of Berlin, Germany
- References: <1000001@hplred.HPL.HP.COM>
- Date: Tue, 15 Dec 1992 15:39:04 GMT
- Lines: 47
-
- This has little to do with pointers to functions; it's only the
- structure-tag-with-prototype-scope question again. (Sorry if
- it's already in the FAQ -- haven't found it.)
-
- curry@hplred.HPL.HP.COM (Bo Curry) writes:
- > typedef struct {
- > void (* displayit)(struct _WINDOW *);
- > } DISPLAYTYPE;
- >
- > static void ShowMyPanes(struct _WINDOW *);
- >
- > int Testit ()
- > {
- > DISPLAYTYPE mypanes;
- > mypanes.displayit= ShowMyPanes;
- > ...
- > }
-
- If you use `struct _WINDOW *' in your code without a previous
- declaration of the same thing in the enclosing scope, you
- `declare a new structure tag'. The scope of a declaration
- (the part of your code it affects) depends on where you write it.
- If you declare a structure inside of a prototype declaration
-
- static void ShowMyPanes(struct _WINDOW *) ;
-
- its scope is only the parameter list of the prototype declaration.
- The two "struct _WINDOW *"s in
-
- static void afunc(struct _WINDOW *);
- static void bfunc(struct _WINDOW *);
-
- need not have anything to do with each other; and neither
- do those in your example.
-
- You fix this by writing
-
- struct _WINDOW;
-
- before the declarations in the enclosing scope; this "starts a new
- scope". From that point, all "struct _WINDOW"s you use will refer to
- that first one, unless you explicitly tell the compiler that you'll
- be talking about a new one -- again using
-
- struct _WINDOW ;
-
- Jutta Degener (jutta@cs.tu-berlin.de)
-