Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!csd4.milw.wisc.edu!lakesys!chad From: chad@lakesys.UUCP (Chad Gibbons) Newsgroups: comp.lang.c Subject: Re: vector initialization Keywords: vectors, char** Message-ID: <698@lakesys.UUCP> Date: 8 Jun 89 13:14:06 GMT References: <687@lakesys.UUCP> <17940@mimsy.UUCP> <11883@bloom-beacon.MIT.EDU> Reply-To: chad@lakesys.UUCP (Chad Gibbons) Distribution: usa Organization: Lake Systems - Milwaukee, Wisconsin Lines: 43 In article <11883@bloom-beacon.MIT.EDU> scs@adam.pika.mit.edu (Steve Summit) writes: |The other way is to modify the declaration, so that you don't |need a pointer: | typedef struct { | char *words[MAXWORDS]; | int (*fcn)(); | short flags; | } COM; | COM foo[] = { | {{ "one", "two", "three", NULL }, do_num, 0,}, | {{ "exit", "quit", NULL }, quit, 0,}, | }; |This has the advantage that you don't need to think of names for |the placeholder pointers. It has the disadvantages that the |number of entries is limited, and space is wasted if there are |many lists with considerably fewer than MAXWORDS entries. Of course this disadvantage (wasted space) takes away from the reason of using the char ** type to begin with. A single entry might have as few as one entry and has many as _fifty_--lots and lots of wasted space there, unfortunately. It would be quite nice to be able to specify the list the same way one does when initializing an array of pointers, but the world doesn't always work the way you want it to. |The method using dummy arrays, which Chris illustrated, is |generally preferable, especially if you don't mind making up |names. Yes; the extra names don't make a difference to me--they can be declared static in a given module and then you wouldn't have to worry about someone "forgetting" what the name you used was and wind up using it for something else, not that this would matter or anything. Of course, once you find out your compiler only supports 4K of literal strings, and you need at least 16K worth, this doesn't matter any more. That is somewhat of a good thing; imagine trying to do a linear-type search through a 16K list _all the time_. If I have to store them external to the code, at least I can throw them into some type of structure where searching goes quickly. -- D. Chadwick Gibbons, chad@lakesys.lakesys.com, ...!uunet!marque!lakesys!chad