char *** initialization and compiler problem

hokey at plus5.UUCP hokey at plus5.UUCP
Sat Mar 14 04:15:25 AEST 1987

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?


# 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[] = {
char *b_list[] = {

/* char ***em_t		/**/
/* char *(*em_t)[]	/**/
/* char *em_t[][]	/**/
char **em_t[]		/**/
	= {
			a_list	/* Just try and initialize with strings here! */

main() {
	int table, entry;
	int size;

	while(scanf("%d %d", &table, &entry) == 2) {
		printf("table %d, entry %d = %s\n",
@//E*O*F emt.c//
chmod u=rw,g=rw,o=r emt.c
exit 0

More information about the Comp.lang.c mailing list