emacs-devel
[Top][All Lists]
Advanced

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

Re: GCC complaints about missing braces around initializer


From: Pavel Janík
Subject: Re: GCC complaints about missing braces around initializer
Date: Wed, 05 Dec 2001 07:09:49 +0100
User-agent: Gnus/5.090004 (Oort Gnus v0.04) Emacs/21.1.50 (i386-suse-linux-gnu)

   From: "Stefan Monnier" <monnier+gnu/address@hidden>
   Date: Tue, 04 Dec 2001 21:55:31 -0500

Hi Stefan,

   > When compiling with -Wall GCC complaints about missing braces around
   > initializers because the code does
   > 
   >    struct foo var[] = { a11, a12, a13, a21, a22, a23 };
   > 
   > instead of
   > 
   >    struct foo var[] = { {a11, a12, a13}, {a21, a22, a23} };
   > 
   > is there a reason why the code is written this way or can I safely
   > change it to something that GCC likes better ?

when we decide to use the second one, please do not spend your time on
it. I have already did that and use it for about four months now (with many
similar changes - if you use -Wall, you know what I'm talking about ;-). So
I can do it and you can concentrate on things which need more Emacs
know-how (that you have and I am still missing sometimes :-).

   > It seems like it should be fair since the syntax preferred by GCC
   > is already used in various places, but I'd rather make sure,
   > because my memory of C's history is too fuzzy.

The similar applies to:

      if (c1 > 0 && c1 < 32 || c2 > 0 && c2 < 32)
        return -1;

gcc here warns:

charset.c:236: warning: suggest parentheses around && within ||

This is however perfectly legal C. Although I (and gcc too ;-) prefer to
use

      if ((c1 > 0 && c1 < 32) || (c2 > 0 && c2 < 32))
        return -1;

which is more readable and clear for humans.

gcc issues some warning also here:

  while (str = fgets (string, BUFSIZ, in))
    printf ("%s", str);

warning: suggest parentheses around assignment used as truth value

So to prevent it, one should wrote:

  while ((str = fgets (string, BUFSIZ, in)))
    printf ("%s", str);

I have already patches for similar things in my tree.
-- 
Pavel Janík

/* Thanks to Rob `CmdrTaco' Malda for not influencing this code in any
 * way.
 */
                  -- 2.4.3 net/core/netfilter.c



reply via email to

[Prev in Thread] Current Thread [Next in Thread]