home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18405 < prev    next >
Encoding:
Text File  |  1992-12-15  |  1.8 KB  |  59 lines

  1. Newsgroups: comp.lang.c
  2. 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
  3. From: jutta@opal.cs.tu-berlin.de (Jutta Degener)
  4. Subject: Re: Pointer to Function Question
  5. Message-ID: <1992Dec15.153904.13231@cs.tu-berlin.de>
  6. Sender: news@cs.tu-berlin.de
  7. Organization: Techn. University of Berlin, Germany
  8. References: <1000001@hplred.HPL.HP.COM>
  9. Date: Tue, 15 Dec 1992 15:39:04 GMT
  10. Lines: 47
  11.  
  12. This has little to do with pointers to functions; it's only the
  13. structure-tag-with-prototype-scope question again.   (Sorry if
  14. it's already in the FAQ -- haven't found it.)
  15.  
  16. curry@hplred.HPL.HP.COM (Bo Curry) writes:
  17. > typedef struct {
  18. >    void (* displayit)(struct _WINDOW *);
  19. > } DISPLAYTYPE;
  20. >
  21. > static void ShowMyPanes(struct _WINDOW *);
  22. >
  23. > int Testit ()
  24. > {
  25. >    DISPLAYTYPE mypanes;
  26. >    mypanes.displayit= ShowMyPanes;
  27. >    ...
  28. > }
  29.  
  30. If you use `struct _WINDOW *' in your code without a previous 
  31. declaration of the same thing in the enclosing scope, you 
  32. `declare a new structure tag'.  The scope of a declaration
  33. (the part of your code it affects) depends on where you write it.
  34. If you declare a structure inside of a prototype declaration
  35.  
  36.     static void ShowMyPanes(struct _WINDOW *) ;
  37.  
  38. its scope is only the parameter list of the prototype declaration.
  39. The two "struct _WINDOW *"s in 
  40.  
  41.     static void afunc(struct _WINDOW *);
  42.     static void bfunc(struct _WINDOW *);
  43.  
  44. need not have anything to do with each other; and neither
  45. do those in your example.
  46.  
  47. You fix this by writing 
  48.     
  49.     struct _WINDOW;
  50.  
  51. before the declarations in the enclosing scope; this "starts a new
  52. scope".  From that point, all "struct _WINDOW"s you use will refer to
  53. that first one, unless you explicitly tell the compiler that you'll
  54. be talking about a new one -- again using
  55.  
  56.     struct _WINDOW ;
  57.  
  58. Jutta Degener (jutta@cs.tu-berlin.de)
  59.