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?

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



More information about the Comp.lang.c mailing list