Re: canon-host.c disagreement (gnulib vs coreutils); zero initializers

2005-06-24 Thread Jim Meyering
Paul Eggert [EMAIL PROTECTED] wrote:
 I noticed the following disagreement between gnulib and coreutils:

 --- gnulib/lib/canon-host.c   2005-05-13 23:03:57 -0700
 +++ cu/lib/canon-host.c   2005-05-14 00:58:06 -0700
...
 I assume that this was due to a warning from gcc -W about a missing
 initializer.  But I prefer the gnulib style: it's easier to read.

Probably.

 How about if we just ask people to not use gcc -W?

 While we're on the subject, I've noticed that glibc is now using this style:

 struct addrinfo hint = { 0, };

 The extra comma is an indication to the reader that we know there are
 missing zeros, and don't care.  This style can be used for any object
 in C89, e.g.:

 mbstate_t initial_state = { 0, };

That's nice to know.  Thanks.

 where we don't know whether mbstate_t is a structure, or an integer,
 and the code works either way.

 So, I propose that we make the following patch to gnulib, and propagate
 this to coreutils:

 2005-06-23  Paul Eggert  [EMAIL PROTECTED]

   * canon-host.c (canon-host): Append trailing , to 0 in
   initializer of struct addrinfo, as an indication that we don't
   care how many members the structure has.

Fine.  Thanks.


___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


Re: canon-host.c disagreement (gnulib vs coreutils); zero initializers

2005-06-24 Thread Simon Josefsson
Paul Eggert [EMAIL PROTECTED] writes:

 The extra comma is an indication to the reader that we know there are
 missing zeros, and don't care.  This style can be used for any object
 in C89, e.g.:

 mbstate_t initial_state = { 0, };

 where we don't know whether mbstate_t is a structure, or an integer,
 and the code works either way.

I recall some compilers complaining about a trailing ','s.  Is it
really OK by C89?  I'm just curious.


___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


Re: canon-host.c disagreement (gnulib vs coreutils); zero initializers

2005-06-24 Thread Jim Meyering
Simon Josefsson [EMAIL PROTECTED] wrote:
 Paul Eggert [EMAIL PROTECTED] writes:

 The extra comma is an indication to the reader that we know there are
 missing zeros, and don't care.  This style can be used for any object
 in C89, e.g.:

 mbstate_t initial_state = { 0, };

 where we don't know whether mbstate_t is a structure, or an integer,
 and the code works either way.

 I recall some compilers complaining about a trailing ','s.  Is it
 really OK by C89?  I'm just curious.

SunOS's /bin/cc was one of the complainers,
but we've all agreed to drop support for it.


___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


Re: canon-host.c disagreement (gnulib vs coreutils); zero initializers

2005-06-24 Thread James Youngman
On Fri, Jun 24, 2005 at 01:16:50PM +0200, Simon Josefsson wrote:

 I recall some compilers complaining about a trailing ','s.  Is it
 really OK by C89?  I'm just curious.

Oddly, it's different for array initialisers and enums, but I can't
remember which is allowed and which is not. 

James.



___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


Re: canon-host.c disagreement (gnulib vs coreutils); zero initializers

2005-06-24 Thread Paul Eggert
Simon Josefsson [EMAIL PROTECTED] writes:

 I recall some compilers complaining about a trailing ','s.  Is it
 really OK by C89?  I'm just curious.

Yes, it is allowed in C89.

Perhaps you're thinking of enumeration specifiers.  The declaration:

enum { zero, };

is not allowed in C89.  (C99 allows the trailing comma here, too --
isn't it wonderful how new features are always being added to C?  :-)

Since there was agreement about the change, I installed it in gnulib
and coreutils.


___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


Re: canon-host.c disagreement (gnulib vs coreutils); zero initializers

2005-06-24 Thread Simon Josefsson
Paul Eggert [EMAIL PROTECTED] writes:

 Simon Josefsson [EMAIL PROTECTED] writes:

 I recall some compilers complaining about a trailing ','s.  Is it
 really OK by C89?  I'm just curious.

 Yes, it is allowed in C89.

 Perhaps you're thinking of enumeration specifiers.  The declaration:

 enum { zero, };

 is not allowed in C89.

Ah, indeed, I now remember that I had hit this problem with some error
value enum's in more than one of my projects.  Thanks!


___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib


canon-host.c disagreement (gnulib vs coreutils); zero initializers

2005-06-23 Thread Paul Eggert
I noticed the following disagreement between gnulib and coreutils:

--- gnulib/lib/canon-host.c 2005-05-13 23:03:57 -0700
+++ cu/lib/canon-host.c 2005-05-14 00:58:06 -0700
@@ -54,8 +54,9 @@ canon_host (char const *host)
 
 #if HAVE_GETADDRINFO
   {
-struct addrinfo hint = { 0 };
+struct addrinfo hint;
 struct addrinfo *res = NULL;
+memset (hint, 0, sizeof hint);
 hint.ai_flags = AI_CANONNAME;
 if (getaddrinfo (host, NULL, hint, res) == 0)
   {

I assume that this was due to a warning from gcc -W about a missing
initializer.  But I prefer the gnulib style: it's easier to read.
How about if we just ask people to not use gcc -W?

While we're on the subject, I've noticed that glibc is now using this style:

struct addrinfo hint = { 0, };

The extra comma is an indication to the reader that we know there are
missing zeros, and don't care.  This style can be used for any object
in C89, e.g.:

mbstate_t initial_state = { 0, };

where we don't know whether mbstate_t is a structure, or an integer,
and the code works either way.

So, I propose that we make the following patch to gnulib, and propagate
this to coreutils:

2005-06-23  Paul Eggert  [EMAIL PROTECTED]

* canon-host.c (canon-host): Append trailing , to 0 in
initializer of struct addrinfo, as an indication that we don't
care how many members the structure has.

--- gnulib/lib/canon-host.c 2005-05-13 23:03:57 -0700
+++ fixed-gnulib/lib/canon-host.c   2005-06-23 16:06:21 -0700
@@ -54,7 +54,7 @@ canon_host (char const *host)
 
 #if HAVE_GETADDRINFO
   {
-struct addrinfo hint = { 0 };
+struct addrinfo hint = { 0, };
 struct addrinfo *res = NULL;
 hint.ai_flags = AI_CANONNAME;
 if (getaddrinfo (host, NULL, hint, res) == 0)


___
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib