Re: [PATCH] dir.c: avoid c99 array initialization
- From
David Kågedal <davidk@lysator.liu.se>
- Date
- Aug 28, 2008, 15:32 UTC
- Message-ID
- <871w09kvew.fsf@lysator.liu.se>
- In-Reply-To
- <G-ipWASixyGW7nvO1KquifehvBB7FNKwjPtIB0ukyEJ1Si1CJWM34w@cipher.nrlssc.navy.mil>
Brandon Casey <casey@nrlssc.navy.mil> writes:
Show 10 quoted lines
> The following syntax:
>
> char foo[] = {
> [0] = 1,
> [7] = 2,
> [15] = 3
> };
>
> is a c99 construct which some compilers do not support even though they
> support other c99 constructs. Use an alternative.But the alternative is much worse. So how important is it to support non-C99 compilers?
Show 28 quoted lines
> ---
> dir.c | 11 ++++++-----
> 1 files changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/dir.c b/dir.c
> index 29d1d5b..14d2eea 100644
> --- a/dir.c
> +++ b/dir.c
> @@ -680,13 +680,14 @@ static int cmp_name(const void *p1, const void *p2)
> */
> static int simple_length(const char *match)
> {
> - const char special[256] = {
> - [0] = 1, ['?'] = 1,
> - ['\\'] = 1, ['*'] = 1,
> - ['['] = 1
> - };
> + char special[256] = { 1, };
> int len = -1;
>
> + special['?'] = 1;
> + special['\\'] = 1;
> + special['*'] = 1;
> + special['['] = 1;
> +
> for (;;) {
> unsigned char c = *match++;
> len++;-- David Kågedal