Re: [Snowball-discuss] {'p','r','o','b','l','e','m'}

From: James Aylett (james-xapian@tartarus.org)
Date: Fri Mar 01 2002 - 17:50:35 GMT


On Fri, Mar 01, 2002 at 05:27:44PM +0000, Richard Boulton wrote:

> On Fri, 2002-03-01 at 16:32, Martin Porter wrote:
> > I've hit a slight snag in converting strings "abc" to structures
> > {'a','b','c'}, in the ANSI C generated from Snowball, which is exemplified
> > by this little program:
>
> Can't you do:
>
> static const symbol string_N[] = {'a','b','c','d', 0};
>
> static struct among B[] =
>
> { { 4, string_N, 12, 12, 0},
> ...
> }
>
> I think you're right that you need to declare the arrays, but I don't
> think you need to have actual initialiser code.

That sounds reasonable. The reason Martin's original code (having the
{'a', 'b', 'c', 'd', 0} initialising a char*) failed is that there was
no array storage being allocated in the initialisation (just storage
for each character constant; contrast to "abcd" which allocates a
string constant, which is equivalent to a constant array of
characters). In the above, you're getting allocation for the array in
the initialiser for string_n (well, it should be string_n not string_N
:-) so everything's okay. It certainly compiles for me, and it makes
sense to me as well.
 
> PS: I think you need to change struct among so that "s" is declared as a
> "const char *", rather than just a "char *". I get warnings, otherwise.

String constants are equivalent to constant arrays of characters, so
assigning one to a non-const character pointer is weakening your
type. Or: I think so too. :)

J

-- 
/--------------------------------------------------------------------------\
  James Aylett                                            zap.tartarus.org
  james@tartarus.org                                        footlights.org

_______________________________________________ Snowball-discuss mailing list Snowball-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/snowball-discuss



This archive was generated by hypermail 2.1.3 : Thu Sep 20 2007 - 12:02:41 BST