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