Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!husc6!seismo!plus5!hokey From: hokey@plus5.UUCP Newsgroups: comp.lang.c Subject: char *** initialization and compiler problem Message-ID: <1721@plus5.UUCP> Date: Fri, 13-Mar-87 13:15:25 EST Article-I.D.: plus5.1721 Posted: Fri Mar 13 13:15:25 1987 Date-Received: Sat, 14-Mar-87 09:03:14 EST Reply-To: hokey@plus5.UUCP (Hokey) Distribution: world Organization: Plus Five Computer Services, St. Louis, MO Lines: 89 A while ago I wanted to provide for more comprehensive error message reporting in some software I was writing. Since sys_errlist is an array of char *, and all the libaries I was building had their own, similar, arrays, I thought it would be "nice" to combine all these tables of messages and pass these messages from library to library, instead of writing code at the interface between each library which converted error messages and codes from "them" to "us" format. This would also give the ability to pass around "multi-line" messages and handle the logging and printing of all error messages from a single point. Oh, it also provides me with the ability to tailor the error messages to different character sets and languages. I ran in to two instant problems. First, I have been *unable* to initialize the master table in any way other than that in the example below. I tried *lots* of combinations of braces. Second, the *only* declaration acceptable to the compiler for the given initialization of the table is the one below. I am using a SysVr2 C compiler, although a friend was similarly frustrated with a compiler on his Sun. He was able to effect a solution using structures, but I haven't had time to really study that approach. I have no idea if the example below will work on other C compilers. Anybody interested in checking out this beastie? Hokey # This is a shell archive. Remove anything before this line, # then unpack it by saving it in a file and typing "sh file". # # Wrapped by hokey on Fri Mar 13 12:10:36 CST 1987 # Contents: emt.c echo x - emt.c sed 's/^@//' > "emt.c" <<'@//E*O*F emt.c//' /* Error Message Table test program */ extern char *sys_errlist[]; /* as per perror(3C) */ char *a_list[] = { "a0", "a1", "a2", "a3", "a4", "a5", "a6", 0}; char *b_list[] = { "b0", "b1", "b2", "b3", 0}; /* char ***em_t /**/ /* char *(*em_t)[] /**/ /* char *em_t[][] /**/ char **em_t[] /**/ = { sys_errlist , a_list /* Just try and initialize with strings here! */ , b_list , 0 }; main() { int table, entry; int size; while(scanf("%d %d", &table, &entry) == 2) { printf("table %d, entry %d = %s\n", table, entry, em_t[table][entry] );} exit(0);} @//E*O*F emt.c// chmod u=rw,g=rw,o=r emt.c exit 0 -- Hokey