I occasionally run across a comment in wiretap/file.c where the author
wants to declare a "const" array of pointers to functions. Well, what
we can have is an array of const pointers, according to our friend
cdecl. Here's what the existing code declares:
cdecl> explain int (*open[])()
declare open as array of pointer to function returning int
And here's what the updated code declares:
cdecl> explain int (*const open[])()
declare open as array of const pointer to function returning int
Graeme Hewson
--- file.c.orig Thu Jan 30 22:38:47 2003
+++ file.c Mon May 26 11:29:46 2003
@@ -80,18 +80,13 @@
* If the routine handles this type of file, it should set the "file_type"
* field in the "struct wtap" to the type of the file.
*
- * XXX - I need to drag my damn ANSI C spec in to figure out how to
- * declare a "const" array of pointers to functions; putting "const"
- * right after "static" isn't the right answer, at least according
- * to GCC, which whines if I do that.
- *
* Put the trace files that are merely saved telnet-sessions last, since it's
* possible that you could have captured someone a router telnet-session
* using another tool. So, a libpcap trace of an toshiba "snoop" session
* should be discovered as a libpcap file, not a toshiba file.
*/
-static int (*open_routines[])(wtap *, int *) = {
+static int (*const open_routines[])(wtap *, int *) = {
/* Files that have magic bytes in fixed locations. These
* are easy to identify.
*/