bug-gnulib
[Top][All Lists]
Advanced

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

Re: [PATCH] ssize_t: fix definition on mingw


From: Bruno Haible
Subject: Re: [PATCH] ssize_t: fix definition on mingw
Date: Thu, 05 Apr 2012 12:10:28 +0200
User-agent: KMail/4.7.4 (Linux/3.1.0-1.2-desktop; KDE/4.7.4; x86_64; ; )

Hi Eric,
> We were blindly defining ssize_t to int.  On mingw64, this is the
> correct size, but the wrong rank, which leads gcc to issue warnings
> for %zd printf directives.
> 
> * m4/ssize_t.m4 (gt_TYPE_SSIZE_T): Match rank of size_t.

This patch will not help to fix Daniel Berrange's problem. In mingw
and mingw64, ssize_t is defined by <sys/types.h>, and gnulib will not
override it.

Test program:
==================== foo.c =================
#include <sys/types.h>
size_t a;
ssize_t b;
============================================

With mingw of 2009:

$ gcc -mno-cygwin -c foo.c
$ gcc -mno-cygwin -E foo.c | grep size_t
typedef unsigned int size_t;
typedef long _ssize_t;
typedef _ssize_t ssize_t;
size_t a;
ssize_t b;

With mingw of 2011:

$ i686-pc-mingw32-gcc -c foo.c
$ i686-pc-mingw32-gcc -E foo.c | grep size_t
typedef unsigned int size_t;
typedef int _ssize_t;
typedef _ssize_t ssize_t;
size_t a;
ssize_t b;

With mingw64 of 2011:

$ i686-w64-mingw32-gcc -c foo.c
$ i686-w64-mingw32-gcc -E foo.c | grep size_t
typedef unsigned int size_t;
typedef int ssize_t;
size_t a;
ssize_t b;

This is consistent with what doc/posix-headers/sys_types.texi says:

@item
The type @code{ssize_t} is not defined on some platforms:
MSVC 9.

> Bruno, is this okay to apply?

No. Even if it would help, there would be a few nits:

> +    AC_CACHE_CHECK([for rank of size_t], [gt_cv_size_t_rank],

Better say "integer conversion rank", since that's the term ISO C 99
uses (section 6.3.1.1).

> +      [AC_COMPILE_IFELSE(
> +        [AC_LANG_PROGRAM(
> +          [[#include <sys/types.h>
> +          #ifdef __cplusplus

Intentation problem.

> +          extern "C" {
> +          #endif
> +            int foo(unsigned long bar);
> +            int foo(size_t bar);

You cannot look at size_t to determine what ssize_t should be: On MSVC 9,
<sys/types.h> lacks both size_t and ssize_t.

> +          ]])],
> +       [gt_cv_size_t_rank=long], [gt_cv_size_t_rank=int])])

Another indentation problem.

In summary, I would not do something about it in gnulib. The proper place
for setting up size_t and ssize_t are GCC and <sys/types.h>. If gnulib
would override the definition, it would have side effects on C++ overloading.
For my feeling, that's not worth it. Simply ignore the GCC printf argument
size warnings on mingw. Look at them only on glibc systems.

Bruno




reply via email to

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