C Coding Question

Gary Wisniewski gary at darth.UUCP
Wed Aug 13 01:32:47 AEST 1986


Distribution:


In article <248 at killer.UUCP> tad at killer.UUCP writes:
>Hey, everybody, I discovered a "new" (new to me) way of coding such static
>things as descriptions, helps, and the like.  It goes like this:
>

[At this point, the author includes code which builds a table of char *'s
which are preinitialized and terminated with a NULL ptr, then builds a
function say(char *) which prints out the entire list.]

>
>Here's the question:  Should help and description be declared char *help[]
>or char **help?  Should say() be declared void, or is there some sort of 
>error checking I should implement?  Are there any other suggestions or
>comments?  How about any other neat "tricks" anyone has discovered lately?
>
>						Tad
>--
>Tad Marko


The technique you've discovered is actually a small part of a much more
general facility in C.  For more interesting ideas about ways to create
complex pre-initialized structures and tables, look at K&R, page 124.

As far as your question about "char *help[]" and "char **help": the two
forms are IDENTICAL to virtually every C compiler (that's worth its
salt).  Arrays in C are merely special cases of pointers.  In other
words, both forms are correct.  Section 5.3 of K&R explain this
more fully.  Happy C-ing.

Gary J. Wisniewski
Pittsburgh, PA

Usenet:		{allegra, bellcore, cadre}!pitt!darth!gary



More information about the Comp.lang.c mailing list