Re: [PATCH] dir.c: avoid c99 array initialization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Brandon Casey <casey@xxxxxxxxxxxxxxx> writes:

> 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?

> ---
>  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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux