home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16928 < prev    next >
Encoding:
Internet Message Format  |  1992-11-20  |  1.4 KB

  1. Path: sparky!uunet!sdrc!thor!scjones
  2. From: scjones@thor.sdrc.com (Larry Jones)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Array of pointers to constant functions?
  5. Message-ID: <2299@sdrc.COM>
  6. Date: 20 Nov 92 17:56:59 GMT
  7. References: <41289@sdcc12.ucsd.edu>
  8. Sender: news@sdrc.COM
  9. Lines: 23
  10.  
  11. In article <41289@sdcc12.ucsd.edu>, cs161feu@sdcc10.ucsd.edu (Anthony Minkoff) writes:
  12. > I want to declare an array of pointers to constant functions.  (Is
  13. > that last bit redundant?)  I.e., what I want is an array of pointers
  14. > to functions.  Each of these functions is defined at compile time,
  15. > and I'd rather not have to give a name to each of these functions
  16. > (except, of course, for the name of the array).
  17.  
  18. C functions are like string literals: they're not actually "const", but
  19. you're not allowed to try to change them, either.  The only way you can
  20. even declare a const function is by using a typedef and ANSI C
  21. explicitly makes that undefined behavior.  C does not support anonymous
  22. functions, so you will have to give them all names.  Something like:
  23.  
  24.     static void f1(void) { printf("one\n"); }
  25.     static void f2(void) { printf("two\n"); }
  26.  
  27.     void (*a[])(void) = { f1, f2 };
  28. ----
  29. Larry Jones, SDRC, 2000 Eastman Dr., Milford, OH  45150-2789  513-576-2070
  30. larry.jones@sdrc.com  or  ...uunet!sdrc!larry.jones
  31. Something COULD happen today.  And if anything DOES,
  32. by golly, I'm going to be ready for it! -- Calvin
  33.