Re: [Snowball-discuss] Compiling with VC++ 6?

From: J Smith (
Date: Fri Apr 19 2002 - 15:50:06 BST

I'm pretty sure that zero-length arrays aren't ANSI C. The C99 draft standard

"The [ and ] may delimit an expression or *. If [ and ] delimit an expression
(which specifies the size of an array), it shall have an integer type...
greater than zero."

Although, in C99, you can also use a flexible array to avoid the subscript,
i.e. array[] = { ... }. In C89, you were struck with using an array of at
least size 1.

The gcc manual also mentions that "zero-length arrays are allowed in GNU C...
In standard C, you would have to give the conents a length of 1, which means
either you waste space or complicate the argument to malloc."

Hopefully in the next C standard they'll allow zero-length arrays, as they can
be quite useful at times.

As for the memcmp issue, I've never seen a problem comparing 0 bytes of
[in]valid memory addresses, as I think most implementations of memcmp
probably bail out before even checking any memory if n is 0. (Optimization, I


On April 19, 2002 09:59 am, Martin Porter wrote:
> Dear jsmith,
> You may know that Snowball was recently altered to look after 16 bit
> characters as readily as 8 bit characters, and at that time all these
> {a,b,c...} declarations crept in. Of course, {'a','b','c'} is one character
> shorter than "abc", because there is no zero terminator, hence the problem
> with null lists.
> I can't convince myself that null lists violate ANSI C, but even so:---
> I've altered Snowball so that declarations of the form
> static symbol some_name[0] = { };
> are everywhere suppressed. Where 'some_name' would appear in the code there
> now appears '0', and this works in all the 'among' structures where null
> strings get used.
> There is another context in which null strings may be generated, although
> the Snowball scripts on the website contain no examples of this. It
> ultimately causes a call to
> memcmp(p,q,n);
> where n==0 and q==0. With my gcc, memcmp(x,y,0) always returns 0, as you
> would expect, and I think I'll leave it like that. Or does anyone know of
> situations where memcmp crashes if n==0 and p and q are not valid memory
> addresses?
> I've just done a commit to the website. Everything should be in place in a
> few hours.
> Martin

Snowball-discuss mailing list

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